This post has been edited by Decypher: 24 July 2009 - 04:07 AM
Encrypting passwords | solved!
Page 1 of 114 Replies - 808 Views - Last Post: 24 July 2009 - 07:25 AM
#1
Encrypting passwords | solved!
Posted 24 July 2009 - 02:34 AM
Okay..So I've added the md5 encryption to the passwords when they register however, when I try and login with the username and password I registered with it says username and password do not match, which makes sense...so how do I get it to unecrypt when tryin to login? or how to make it recognise it's the right password?
Replies To: Encrypting passwords | solved!
#2
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 02:35 AM
$password=strip_tags($_POST['password']);
if(md5($password)) == [encrypted password] {
..
}
#4
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 02:55 AM
you cant 'unencrypt' md5 encryptions however what no2pencil does is encrypt the passwotrd they are trying to log on with and if that == the one stored in db then the unencrypted versions must be the same, right ? therefore, grant access
#6
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 03:18 AM
hmm did what you said but get user and password do not match:
$user=$_POST["username"];
$pass=strip_tags($_POST['password']);
$pass=md5($pass);
$queryz ="SELECT * FROM login WHERE `username` LIKE '$user'";
$queryz=mysql_query($queryz);
$num = mysql_num_rows($queryz);
if ($num != 0){
$sql="SELECT * FROM login WHERE `username` LIKE '$user'";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result)){ // Start While
$username = $row['username'];
$password = $row['password'];
if(strcasecmp ($username,$user) == 0 && $password != $pass){
echo'Your username and password do not match<br>
<a href="index.php">Return Home</a>';
}else{
if (strcasecmp ($username,$user) != 0 || $password != $pass){
echo'Your username and password do not match<br>
<a href="index.php">Return Home</a>';
}else{
if (strcasecmp ($username,$user) == 0 && $password == $pass){
$_SESSION["userid"] = $row["id"];
header ('Location: login.php');
}
}
}
}
} else {
echo' This User does not exist!<br>
<a href="index.php">Return Home</a>';
#7
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 03:50 AM
nvm found the problem...
I remember reading md5 = 156chars or something long and my field maxed out at 20 lol
The next question is how do I get the passwords that aren't encrypted due to this only being used to being encrypted
I remember reading md5 = 156chars or something long and my field maxed out at 20 lol
The next question is how do I get the passwords that aren't encrypted due to this only being used to being encrypted
#8
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 03:54 AM
Decypher, on 24 Jul, 2009 - 02:50 AM, said:
I remember reading md5 = 156chars or something long and my field maxed out at 20 lol
32 characters
Decypher, on 24 Jul, 2009 - 02:50 AM, said:
The next question is how do I get the passwords that aren't encrypted due to this only being used to being encrypted
You don't, MD5 crypts are one way. You could use a private key system where you can encrypt/decrypt based on a key that you provide, but that's obviously less secure if you're storing the key on your system.
Why would you want to do that anyway? Passwords should only be for comparison when stored in an "open" database.
#9
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 03:57 AM
Some passwords aren't encrypted at the moment due to me only putting this in place..However while I still am updating and making the site, obviously my original account doesn't have an ecrypted password and therefore when it goes to login the passwords don't match as the script now converts the password to md5 encryption.
if that makes sense
if that makes sense
#10
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 04:05 AM
No, re-encrypt your password manually and re-renter it into the database.
#11
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 04:06 AM
nvm found a script that does it 
$q = "SELECT username,password FROM login";
$result = mysql_query($q);
while($data = mysql_fetch_array($result))
{
$username = $data['username'];
$password = $data['password'];
$q="UPDATE login SET password='".md5($password)."' where username='".$username."'";
mysql_query($q);
}
?>
This post has been edited by Decypher: 24 July 2009 - 04:06 AM
#12
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 06:32 AM
just to be technically accurate md5 is not encrypting its hashing. hashing works only one way, meaning that you can hash something but you can not "dehash" it. The idea of hashing is that one sequence of characters (bytes) gives always the same hash.used to check if a file/string has changed since last check.
Using hash for something like passwords is by definition wrong. Furthermore md5 is very very easily broken.meaning that the "cracker" can find out a sequence of characters that produce the same hash.(for more info google md5 bruteforce rainbow tables).
To make a relatively good encrypting function for passwords, you can use some of the phps encryption/decryption functions (i propose using that mcrypt extension).
if you insist using hashing, then use sha1 not md5
Using hash for something like passwords is by definition wrong. Furthermore md5 is very very easily broken.meaning that the "cracker" can find out a sequence of characters that produce the same hash.(for more info google md5 bruteforce rainbow tables).
To make a relatively good encrypting function for passwords, you can use some of the phps encryption/decryption functions (i propose using that mcrypt extension).
if you insist using hashing, then use sha1 not md5
This post has been edited by izrafel: 24 July 2009 - 06:42 AM
#13
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 06:48 AM
cheers for that rafel...I only used md5 as it was the only one I knew...I take it mcrypt and sha1 work in the same way of md5 as in coding wise? so basically replace md5 with mcrypt?
#14
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 06:54 AM
Decypher, on 24 Jul, 2009 - 05:48 AM, said:
cheers for that rafel...I only used md5 as it was the only one I knew...I take it mcrypt and sha1 work in the same way of md5 as in coding wise? so basically replace md5 with mcrypt?
well using md5 is not wrong when used for what it is meant to
if you want i can give you some hints on how to make a good login system
#15
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 06:59 AM
the only problem with the login system was that passwords weren't being encrypted apart from that the login system is great so far...(will get people in to test it throughly though)
will check it out the link thou
will check it out the link thou
#16
Re: Encrypting passwords | solved!
Posted 24 July 2009 - 07:25 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|