Menu
hi,
i am new to php.i am trying to create user registration form. i want to encrypt the password. My friend told me to use MD5().but i dont know how to use it.
And how should i store in the password in the database? ?
[code=php]
$query = <<<EOD
INSERT INTO table_name
(login
, password
)
VALUES ('{$_POST['login']}', PASSWORD('{$_POST['password']}'))
EOD;
[/code]
[code=php]
$query = <<<EOD
SELECT * FROM table_name
WHERE login
= '{$_POST['login']}' AND password
= PASSWORD('{$_POST['password']}')
EOD;
[/code]
[code=php]
$encryptedPassword = md5($_POST['password']);
$query = <<<EOD
INSERT INTO table_name
(login
, password
)
VALUES ('{$_POST['login']}', '$encryptedPassword'
EOD;
[/code]
[code=php]
$encryptedPassword = md5($_POST['password']);
$login = $_POST['login'];
$query = "SELECT * FROM table_name
WHERE login
= '$login' AND `password = '$encryptedPassword'";
$result = mysql_query($query) or die(mysql_error());
if(mysql_num_rows($result))
{
// found a match for login and password
}
else
{
// login/password combination is not in database
}
[/code]
PS: make sure your password field is a 32-character varchar field, as that is the length of the string returned by the md5() function.[/QUOTE]
hi all,
Can any one please help me to decrypt & display the encrypted password(using md5()) from the database....
thanks in advance[/QUOTE]
You cannot decrypt it, md5 is "one-way" encryption. (Actually, it creates a "hash" value from the supplied string, but don't worry about that.) What you do is use the same md5 function to encrypt the user's password when he logs in, then compare that to the already encrypted value in the database:
[code=php]
[/QUOTE]
$encryptedPassword = md5($_POST['password']);
$login = $_POST['login'];
$query = "SELECT * FROMtable_name
WHERElogin
= '$login' AND `password = '$encryptedPassword'";
$result = mysql_query($query) or die(mysql_error());
if(mysql_num_rows($result))
{
// found a match for login and password
}
else
{
// login/password combination is not in database
}
[/code]
This is not directed against you NogDog, but just a question in general...
Why does everywhere say that md5 is "one-way" encryption, and cant be decrypted? A google search a few days ago for something like "md5 encryption" gave me on the first page a link to a md5 decrypter, which wasn't the aim of the search but nevertheless it came up. I tried it and it works perfectly. I know i am just a n00b, and and know very little about encryption, but i would just really like to know what people [i]actually[/i] mean when they say a md5 hash cannot be decrypted?? It just appears totally untrue to me. ?
Thank you
Baloo ?[/QUOTE]
0.1.9 — BETA 5.19