2008-12-26 16 views
7

मुझे आशा है कि एक मानक वर्ग/PHP स्क्रिप्ट है जिसे हम "भूल गए पासवर्ड" कार्यक्षमता के लिए उपयोग कर सकते हैं। ऐसा लगता है कि लगभग हर वेबसाइट में एक है, और मैं इसके विकास के समय को कम करना चाहता हूं।php/mysql पर्यावरण में मानक क्लास या स्क्रिप्ट "उपयोगकर्ता पासवर्ड भूल गया"?

ऐसा लगता है कि एक आम दृष्टिकोण है:

  1. क्लिक पर पासवर्ड
  2. उपयोगकर्ता ईमेल के माध्यम से प्राप्त करता है एक "पासवर्ड रीसेट करें" लिंक भूल
  3. लिंक पर
  4. पर क्लिक करें "नया पासवर्ड" "में टाइपिंग की अनुमति देता है पासवर्ड फिर से लिखें "
  5. जीवन अच्छा

मैं खरोंच से यह करने के लिए नहीं करना चाहती है, कोई है जो के माध्यम से सोचा है उम्मीद कोई भी व्याख्या मुझे पूर्व-मौजूदा कोड पर इंगित कर सकती है। ऐसा लगता है कि यह एक सुंदर मानकीकृत है।

सभी: कुछ प्रतिक्रियाएं मिलीं, लेकिन मुझे उम्मीद है कि कोई शायद एक सुंदर मानक वर्ग या सीएमएस की सिफारिश कर सकता है जो आम तौर पर स्वीकृत सुरक्षा दिशानिर्देशों को पूरा करता है।

+0

हाय, मेरे लिए मेरी नौकरी करें, धन्यवाद –

+0

नहीं, यह अच्छा है। यह बिल्कुल ठीक है चीज के लिए है। प्रमाणीकरण सामग्री सूक्ष्म तरीकों से गलत होने में आसान और आसान है जो तब तक दिखाई नहीं दे रही जब तक आपकी साइट हैक की गई थी। एक मानक स्क्रिप्ट के लिए जांच कर रहा है जिसे वह इस बारे में नहीं जानता है इस काम में नौकरी का हिस्सा है। –

+0

दोस्तों, मेरी पहली टिप्पणी के लिए खेद है –

उत्तर

0

आप इसे विभिन्न प्रकार के ढांचे/सीएमएस से चुरा सकते हैं। Drupal, Kohana, आदि ...

+0

मैं qcodo का उपयोग कर रहा हूं जो ऐसा नहीं लगता है ... जो मैंने सोचा था कि अजीब था .... – AFG

11

मैं पासवर्ड रीसेटिंग के लिए अपनी स्क्रिप्ट का उपयोग करता हूं।

// query is my own SQLite3 wrapper function which ensures I have a valid database connection then executes the SQL. 
// I would imagine small changes will be needed to the SQL for MY SQL. 
query("create table reset_password (user_id integer not null default 0, key text not null default '', time integer not null default 0)"); 
query("create unique index reset_password_user_id on reset_password (user_id)"); 
query("create index reset_password_key on reset_password (key)"); 

फिर जब एक पासवर्ड रीसेट करने की आवश्यकता है, तो निम्न कोड कहा जाता है::

मैं एक user_id, एक यादृच्छिक कुंजी और एक बार हुआ है कि पासवर्ड रीसेट शुरू स्टोर करने के लिए एक तालिका बनाने

// $user_id must be an integer that matches a valid user's ID. 
function reset_password($user_id) { 
    query("delete from reset_password where user_id = $user_id"); 
    $key = substr(base64_encode(crypt('', '')), 0, 32); 
    query("insert into reset_password values ($user_id, '$key', " . time() . ")"); 
    // fetch is my own wrapper function to fetch a row from the query. 
    $f = fetch(query("select username from users where id = $user_id")); 
    // smtp is my own function, you will probably want to use the php mail function. 
    smtp(
    "[email protected]", // sender 
    $f['username'], // recepient 
    "From: The example.com Web Site <[email protected]>\r\n" . // email headers 
    "To: {$f['username']} <{$f['username']}>\r\n" . // actual email address <put a nice friendly name in here if you have the the information> 
    'Subject: Reset Password' . "\r\n" . 
    "\r\n" . 
    "Hello\r\n" . // email body 
    "\r\n" . 
    "A request has been made to reset your example.com web site password.\r\n" . 
    "\r\n" . 
    "To complete the request, click on the following link within 48 hours of the transmision of this email and follow the on screen instructions.\r\n" . 
    "\r\n" . 
    /// URL is defined as the root of the URL used in the email, in this example it would be "http://example.com/" 
    URL . "index.php?page=reset-password&user_id=" . urlencode($user_id) . "&key=" . urlencode($key) . "\r\n" . 
    "\r\n" . 
    "Kind regards,\r\n" . 
    "\r\n" . 
    "The example.com Web Site" 
); 
} 

जब ईमेल में लिंक एक पृष्ठ क्लिक किया जाता है प्रदर्शित किया जाता है जो निम्नलिखित शामिल हैं:

// form, input_hidden, table, tr, td, label, input_password and input_submit are my own wrappers which return the appropriate HTML with escaped values where required. 
echo 
    form('reset-password/ok', 
    input_hidden('user_id', $_GET['user_id']) . 
    input_hidden('key', $_GET['key']) . 
    table(
     tr(
     td(label('New Password')) . 
     td(input_password('new_password', '')) 
    ) . 
     tr(
     td(label('Confirm Password')) . 
     td(input_password('confirm_password', '')) 
    ) 
    ) . 
    input_submit('ok', 'OK') 
); 

जब ऊपर फ़ॉर्म सबमिट निम्नलिखित निष्पादित होने

// The reset_password_message function displays the message to the user. 
if (!isset($_POST['user_id'])) { 
    reset_password_message('You must enter a user ID. Please try again.'); 
} else if (!isset($_POST['key'])) { 
    reset_password_message('You must enter a key. Please try again.'); 
} else if (!isset($_POST['new_password']) || !$_POST['new_password']) { 
    reset_password_message('You must enter a new password. Please try again'); 
} else if (!isset($_POST['confirm_password']) || $_POST['new_password'] != $_POST['confirm_password']) { 
    reset_password_message('The new password and the confirmation do not match. Please try again.'); 
} else if (!$f = fetch(query("select time from reset_password where user_id = " . (integer)$_POST['user_id'] . " and key = '" . escape($_POST['key']) . "'"))) { 
    reset_password_message('The user ID and key pair are invalid. Please try again.'); 
} else if ($f['time'] < time() - 60 * 60 * 24 * 2) { // 60 seconds * 60 minutes * 24 hours * 2 days (48 hours as explained in the email sent to the user above). 
    reset_password_message('The user ID and key pair have expired. Please try again.'); 
} else { 
    query("update users set password = '" . crypt($_POST['new_password']) . "' where id = " . (integer)$_POST['user_id']); 
    reset_password_message('Your password has been reset. Please login.'); 
} 

आप के बजाय "अपने खुद के रोलिंग" इस कोड का उपयोग करने के लिए स्वागत कर रहे हैं, लेकिन आप कुछ कार्यों को जोड़ने में कुछ बदलाव करने की जरूरत है या होगा इसे पूरा करने के लिए।

+0

हैलो स्टेसी रिचर्ड्स, मैं आपकी विधि का पालन कर रहा हूं। मुझे बताएं, मुझे एक ही ई-मेल का उपयोग करके एकाधिक उपयोगकर्ता नामों को कैसे संभालना चाहिए? मेरा मानना ​​है कि मुझे प्रत्येक "उपयोगकर्ता नाम" और फिर वितरण मेल के लिए एक अद्वितीय "यादृच्छिक कुंजी" उत्पन्न करना चाहिए ... धन्यवाद – Darkeden

संबंधित मुद्दे