Jump to content

Recommended Posts

Tried to use md5 for encryption for a register/login system. Everything works fine in the register script but when trying

to evaluate the password on the login page I don't get the same hash as before with the exact same 'password'. Tried sha1 also

and got the same result??? Can this have something to do with the charset??

 

Including snippets from the code

 

login validation script snippet:

[pre]require('../include/connect_db.php');

$sql = 'SELECT uid, email, password FROM sc_users WHERE email = "' . $_POST[txtEmail] . '"';

$result = mysql_query($sql) or die ('Fel på SQL syntax');

$count = mysql_num_rows($result);

 

if($count != 0) {

// Email Registred, check password and set cookie.

$rad = mysql_fetch_array($result);

 

$hash_password = chop(md5($_POST[txtPassword]));

echo $hash_password . '<br />';

echo $rad[password];

 

if($hash_password == $rad[password]) {

//echo ('<br /> Lösenordet stämmer <br />');

} else {

//echo ('lösenordet stämmer inte <br />');

}[/pre]

 

 

 

The register script:

[pre]$encrypted_password = chop(md5($_POST[txtPassword])); // Encrypt password[/pre]

Link to comment
https://forums.phpfreaks.com/topic/82940-solved-encryption-problem/
Share on other sites

Do you actually get a different md5 password echo'd back? to the one that's in the database?

 

 

 

Try changing

 

if($count != 0) {

 

to

 

if($count !== 0) {

 

 

 

Also when calling an array using the key name outside of double quotes use quotes e.g. $rad['password']

 

 

Try this

 

require('../include/connect_db.php');
$sql = 'SELECT uid, email, password FROM sc_users WHERE email = "' . $_POST[txtEmail] . '"';
$result = mysql_query($sql) or die ('Fel på SQL syntax');
$count = mysql_num_rows($result);

if($count !== 0) {
   // Email Registred, check password and set cookie.
   $rad = mysql_fetch_array($result);
   
   $hash_password = chop(md5($_POST['txtPassword']));
   echo $hash_password . '
';
   echo $rad[password];
   
   if($hash_password == $rad['password']) {
      //echo ('
Lösenordet stämmer 
');
   } else {
      //echo ('lösenordet stämmer inte 
');
   }

 

Regards

Liam

First of all, thanx for all quick responds...I made the exampel encryption as you said and this is the response...

 

the word apple..

as rendered in the login script: d41d8cd98f00b204e9800998ecf8427e

as rendered and stored int DB: 1f3870be274f6c49b3e31a0c6728957f

 

the field in the db i varchar 50. As I've understood. the md5 hash has 32 in length.

 

Can't figure one thing out tough...the meta data has charset utf-8...and changed to this in db...didn't help.

maybe i missunderstand all that....pretty new at php and mysql.

what if u just have a simple test page

 

<?php
echo md5($_POST['txtPassword']);
?>

 

then refresh a couple of times, does this change? also exit the browser to start a new session and test.

 

if that never changes then its a problem in the way you insert to your database.. your not md5'in the password then encrypting when inserting in the table are you?

 

 

Regards

Liam

C:\Users\Corbin>php -r "echo md5('apple');"
1f3870be274f6c49b3e31a0c6728957f
C:\Users\Corbin>php -r "echo md5('');"
d41d8cd98f00b204e9800998ecf8427e
C:\Users\Corbin>

 

Just as a I suspected....  The value of the password entered isn't being passed to the md5 call in the script....

 

Can you show us your form?

Thank you for your help...

 

Kind of embarising error.

 

Earlier changed the name of the Textfield but forgot to upload the the file.

The return I got at the login script must have been null from the post variable that didn't exist, or something like that.

 

Again, sorry for taking up your time...

 

 

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.