JJohnsenDK Posted November 17, 2006 Share Posted November 17, 2006 HeyIm 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? Quote Link to comment Share on other sites More sharing options...
Orio Posted November 17, 2006 Share Posted November 17, 2006 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. Quote Link to comment Share on other sites More sharing options...
taith Posted November 17, 2006 Share Posted November 17, 2006 [code]$_POST['upass'] = md5($_POST['upass']);[/code]that cant happen... put[code]$pass= md5($_POST['upass']);.[/code]then[code]$query="select * from user where uname='".$_POST['uname']."' and pw='".$pass."' ";[/code] Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted November 17, 2006 Author Share Posted November 17, 2006 Thanks alot... Fast and great help, nice ;D ... How do i set as RESOLVED? if there are a system like that here, anyways. Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted November 17, 2006 Share Posted November 17, 2006 just add "SOLVED: " in the topic title Quote Link to comment Share on other sites More sharing options...
taith Posted November 17, 2006 Share Posted November 17, 2006 no problem... i try ;-) for any specific questions... feel free to pm me :-) Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted November 17, 2006 Author Share Posted November 17, 2006 Thanks alot.. Im not allowed to write pm tho :-\ Quote Link to comment Share on other sites More sharing options...
taith Posted November 17, 2006 Share Posted November 17, 2006 oops Quote Link to comment 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.