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? Link to comment https://forums.phpfreaks.com/topic/27603-resolved-login-with-md5-encryption/ 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. Link to comment https://forums.phpfreaks.com/topic/27603-resolved-login-with-md5-encryption/#findComment-126231 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] Link to comment https://forums.phpfreaks.com/topic/27603-resolved-login-with-md5-encryption/#findComment-126232 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. Link to comment https://forums.phpfreaks.com/topic/27603-resolved-login-with-md5-encryption/#findComment-126249 Share on other sites More sharing options...
DaveLinger Posted November 17, 2006 Share Posted November 17, 2006 just add "SOLVED: " in the topic title Link to comment https://forums.phpfreaks.com/topic/27603-resolved-login-with-md5-encryption/#findComment-126251 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 :-) Link to comment https://forums.phpfreaks.com/topic/27603-resolved-login-with-md5-encryption/#findComment-126253 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 :-\ Link to comment https://forums.phpfreaks.com/topic/27603-resolved-login-with-md5-encryption/#findComment-126264 Share on other sites More sharing options...
taith Posted November 17, 2006 Share Posted November 17, 2006 oops Link to comment https://forums.phpfreaks.com/topic/27603-resolved-login-with-md5-encryption/#findComment-126274 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.