faqts : Computers : Programming

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

85 of 128 people (66%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

how to create password in PHP?

Jul 5th, 2008 02:45
Taksh Verdhan, Designer Mike, Rachit Bagda, Shashank Tripathi, Matthew Walker, pid apid, http://www.rachit.com, http://www.freelance-web-design-india.com


This will give you a fairly unique, unguessable string: 
    <?  $uniqueString = md5(uniqid(rand(),1));  ?>
http://freemyspacelayouts4u.blogspot.com/
http://surf-wear.blogspot.com/
http://www.autopartsdirectory.info
http://www.reversecellphonedirectory7.info
http://www.webcodirectory.com
http://www.freewebsitesubmission.info/
You can generate very secure encrypted passwords by using the MD5 
function. It is a one-way hashing algorithm (described in more detail 
here: http://snipurl.com/m or http://php.net/md5). You need to md5 
something, which could be a random uniqid (as in the example above) or 
some other word (e.g., user's name), or the current time from 
microtime() function, or concatenations thereof (as suggested by the 
original posters of this FAQT). 
However, please note that md5() function generates 32 characters and 
you 
need to use all the 32 characters to retain the uniqueness. Of course, 
if you don't really need random, unique passwords then a commonly used 
way is to have your users submit a form with their intended password 
while registering, MD5 it and then store it into the database. Later, 
every time they login, you can md5() what they entered, then compare 
it 
with what you have in the database. E.g.,
   $userId       = $_POST['id'];      // From HTML form
   $userPassword = $_POST['password'];   
   $sql = "select * from users 
           where 
               id       = '$userId' 
           and password = MD5('$userPassword') ";
    ...etc...
SOME NOTES: 
1. If you want to implement the "Forgot Password?" functionality, then 
you will need to generate a new temporary password and email it to the 
user, with a link to come back and edit it. 
2. If you use PHP 4.3.0 or above, you may also want to check out the 
SHA1() function -- http://php.net/sha1 or http://snipurl.com/sha1_info
http://www.rachit.com
I guess you got to explain little more.
http://www.freelance-web-design-india.com