Foser Posted May 31, 2007 Share Posted May 31, 2007 I'm looking for a slight tutorial about how to encrypt a password in mysql and decrypt it so when you want to login it's simple. Also I'd like to find a simple tutorial on how to make a basic login with sessions to few 3-4 pages. thanks Quote Link to comment https://forums.phpfreaks.com/topic/53712-mysql-password-encryption-and-decryption/ Share on other sites More sharing options...
chocopi Posted May 31, 2007 Share Posted May 31, 2007 Well the best way to encrypt a password is through md5 and sessions are quite tricky to get used to so I would look at: Sessions So with the md5 you would want your password to be something like this: <?php $password = $_POST['password']; $password = md5($password); ?> <html> <body> <form name="password" action="<?PHP_SELF?>" method="post"> <input type="password" name="password" value="$password"> <input type="submit" name="submit" value="Submit"> </form> </body> </html> <?php // Insert assuming you already connected to the database $query = "INSERT INTO tablename (fieldname) VALUES('$password')"; mysql_query($query) or die(mysql_error()); ?> And then for the login have: <?php $username = $_POST['username']; $password = $_POST['password']; $password = md5($password); // Check if combo is in database $query = mysql_query("SELECT fieldname FROM tablename WHERE fieldname='$username' && fieldname='$password'"); $result = mysql_num_rows($query); if($result > 0){ echo ("Congrats"); } else { echo ("Invalid"); } ?> <html> <body> <form name="login" action="<?PHP_SELF?>" method="post"> <input type="username" name="username" value="$username"> <input type="password" name="password" value="$password"> <input type="submit" name="submit" value="Submit"> </form> </body> </html> This code is completly untested and probably has some faults, but try it and report back Hope it helps ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/53712-mysql-password-encryption-and-decryption/#findComment-265464 Share on other sites More sharing options...
Daniel0 Posted May 31, 2007 Share Posted May 31, 2007 I'm looking for a slight tutorial about how to encrypt a password in mysql and decrypt it so when you want to login it's simple. There is no need to decrypt again. Use a one-way hashing algorithm such as SHA-1 or MD5. Then when the user enter their password to login again they you would just encrypt the entered password and compare it with the already encrypted password stored in the database. Quote Link to comment https://forums.phpfreaks.com/topic/53712-mysql-password-encryption-and-decryption/#findComment-265465 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.