Password

A

Anonymous

Guest
how to encryp and decryp a password ? and how to auto generate an ID number (6 digit) with 2 charater and 4 number? thanks
 
Typically you encrypt passwords with an unique, irreversible hash like md5(), crc32(), or sha1(). You store the hashed password in your database and when the user enters the password to login, you hash it as well and see if they match. You don't decrypt them.

To generate unique ids, you can use uniqid(), but it won't return a number to your specification. When you say "with 2 characters and 4 numbers", what exactly do you mean? Is there a particular format you're after?
 
the example is "MM0002",

encryp the password to prevent user to see,

but to decryp the password to check for validation when a user want to edit the password

any code to decryp a password?
 
You never decrypt the password, because it's not necessary. If you encrypt the password the user enters on the login page, it will match the encrypted copy in the database, and you know it's correct. Allowing passwords to be decrypted presents too much of a security risk and no advantages.

Your example of an automatically-generated id ("MM0002") doesn't tell me anything. Are the numbers and letters random? Or sequential? Is the MM constant? How, exactly, do you want them generated?
 
example is
1."MM0001"
2."MM0002"
3."MM0003"
...
...

...

...

...

thanks
 
So they all start with MM? Then why have the MM at all? Get rid of it and just use a MySQL AUTO_INCREMENT column.

Otherwise every time you do an INSERT you're going to have to look up the largest value, which is going to be a hassle and slow things down.
 
kiwi said:
the example is "MM0002",

encryp the password to prevent user to see,

but to decryp the password to check for validation when a user want to edit the password

any code to decryp a password?
try use thi algorythm:

regitration:
1) inputed password
2) encryp the password and add to DB

validation:
1) inputed password
2) compare: user entered encryp(password) and DB record
 
Back
Top