Jump to content

*RESOLVED* Login with md5 encryption


JJohnsenDK

Recommended Posts

Hey

Im trying to make a login system. I encrypt the password into MySql database with the md5() function, that works just great. But how do i turn the encryption around and unencrypt the password when the user needs to login?

At the moment i'm using this code. I might be totally off course, but here it is:

[code]if(isset($_POST['submit'])){
if( empty($_POST['uname']) && (empty($_POST['upass']))){
header( "Location:Messages.php?msg=1" );
exit();
}

$_POST['upass'] = md5($_POST['upass']);

//Connecter til MySql Databasen.
include('config.php');
$query="select * from user where uname='".$_POST['uname']."'  and pw='".$_POST['upass']."' ";
$result=mysql_query($query);

$num=mysql_num_rows($result);
if($num>0 ){

//Laver sessions om til variabler
$mytime=time();
$mytime=date("H:i:s A",$mytime);
$_SESSION['time'] = $mytime;
$_SESSION['status'] = 'logged';
$_SESSION['username'] = $n;
//Sender brugeren videre til welcome.php hvis bruger og pass er rigtig
header("location:welcome.php");
exit;
}else{
$_SESSION['status'] = 'not logged';
header( "Location:Messages.php?msg=2" );
exit();
}
}[/code]

Im using this line $_POST['upass'] = md5($_POST['upass']); to unencrypt the password, but it doesnt work so its propperly not right. Anyone who can figure out what i should use insted?
Link to comment
Share on other sites

md5 cannot be decrypted. md5 is a [url=http://en.wikipedia.org/wiki/Cryptographic_hash_function]hashing[/url] function.
If you want to check if a login is correct, md5 the given password (the one used to log in) and compare the two hashes.

Orio.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.