Jump to content

Recommended Posts

Hi, im currently building a login system for my website.

When a user registers i have their password sha1 encoded by using this code;

$b = $_POST['requiredpassword'];
$encrypt = sha1($b);

mysql_query ("INSERT INTO aUsers (email, password, fname, lname, newsletter)
			VALUES ('$a', '$encrypt', '$c', '$d', '$e')");

 

the other fields i deleted from this post as they aren't relevant.

Anyway, when i check the fields in the database it works, all the passwords are unreadable.

 

So now with my login script i have this;

include('phpinclude.php');
connect();		
session_start();

$a = $_POST["email"];
$b = sha1($_POST["password"]);

$result = mysql_query("SELECT * FROM aUsers WHERE email='$a' AND password='$b'");
disconnect();
if(mysql_num_rows($result)==0)
{

 

Now this doesn't work, every time i try to login, i just get no results returned. I tried without the sha1 encoding just to check the login script did work correctly, and it did work without it.

 

The thing is ive used this almost identical script before to login using sha1, and it worked. Why isn't this working now? Can anyone shed some light?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/197359-problem-with-sha1-encoding-login/
Share on other sites

Good advice, after outputting the data i had realised a small mistake within the database, i had set the password field to 15 characters yet the sha1 encoding was 40 chars long.

so i extended the limit to 50, and now it works.

 

Thanks a lot for the quick responses.

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.