14 Replies - 808 Views - Last Post: 24 July 2009 - 07:25 AM Rate Topic: -----

#1 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

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?

This post has been edited by Decypher: 24 July 2009 - 04:07 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Encrypting passwords | solved!

#2 no2pencil  Icon User is offline

  • Original Digital Gansta
  • member icon

Reputation: 4463
  • View blog
  • Posts: 24,906
  • Joined: 10-May 07

Re: Encrypting passwords | solved!

Posted 24 July 2009 - 02:35 AM

$password=strip_tags($_POST['password']);
if(md5($password)) == [encrypted password] {
  ..
}


Was This Post Helpful? 1
  • +
  • -

#4 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 40
  • View blog
  • Posts: 876
  • Joined: 08-August 08

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
Was This Post Helpful? 1
  • +
  • -

#5 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: Encrypting passwords | solved!

Posted 24 July 2009 - 03:04 AM

ahh okay cheers :)
Was This Post Helpful? 0
  • +
  • -

#6 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

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>';


Was This Post Helpful? 0
  • +
  • -

#7 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

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
Was This Post Helpful? 0
  • +
  • -

#8 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 994
  • View blog
  • Posts: 3,547
  • Joined: 05-June 09

Re: Encrypting passwords | solved!

Posted 24 July 2009 - 03:54 AM

View PostDecypher, 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 :)

View PostDecypher, 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.
Was This Post Helpful? 0
  • +
  • -

#9 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

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
Was This Post Helpful? 0
  • +
  • -

#10 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 994
  • View blog
  • Posts: 3,547
  • Joined: 05-June 09

Re: Encrypting passwords | solved!

Posted 24 July 2009 - 04:05 AM

No, re-encrypt your password manually and re-renter it into the database.
Was This Post Helpful? 0
  • +
  • -

#11 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

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

Was This Post Helpful? 0
  • +
  • -

#12 izrafel  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 84
  • Joined: 24-July 09

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

This post has been edited by izrafel: 24 July 2009 - 06:42 AM

Was This Post Helpful? 0
  • +
  • -

#13 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

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?
Was This Post Helpful? 0
  • +
  • -

#14 izrafel  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 84
  • Joined: 24-July 09

Re: Encrypting passwords | solved!

Posted 24 July 2009 - 06:54 AM

View PostDecypher, 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 ;). sha1 is also a hashing algorithm. for mcrypt see this
if you want i can give you some hints on how to make a good login system :).
Was This Post Helpful? 0
  • +
  • -

#15 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

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 :)
Was This Post Helpful? 0
  • +
  • -

#16 izrafel  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 84
  • Joined: 24-July 09

Re: Encrypting passwords | solved!

Posted 24 July 2009 - 07:25 AM

View PostDecypher, on 24 Jul, 2009 - 05:59 AM, said:

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 :)

ok ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1