Jump to content

Recommended Posts

my _post password is not matching the password in the DB? here is my code anybody see any glaring issues?

 

if (isset($_POST['submit'])) { // if form has been submitted

// makes sure they filled it in

if(!$_POST['username'] | !$_POST['pass']) {

die('You did not fill in a required field.');

}

// checks it against the database

if (!get_magic_quotes_gpc()) {

$_POST['email'] = addslashes($_POST['email']);

}

$check = mysql_query("SELECT * FROM users WHERE email = '".$_POST['username']."'")or die(mysql_error());

//Gives error if user dosen't exist

$check2 = mysql_num_rows($check);

if ($check2 == 0) {

die('That is not a vaild username.');

}

while($info = mysql_fetch_array( $check ))

{

$_POST['pass'] = stripslashes($_POST['pass']);

$info['password'] = stripslashes($info['password']);

$_POST['pass'] = md5($_POST['pass']);

//gives error if the password is wrong

if ($_POST['pass'] != $info['password']) {

die('Incorrect password, please try again.');

}else

Link to comment
https://forums.phpfreaks.com/topic/141830-password-issues/
Share on other sites

A few things I notice:

<?php
if(!$_POST['username'] | !$_POST['pass']) {

// should be:
if(!$_POST['username'] || !$_POST['pass']) {
?>

 

and:

<?php
// you don't need this, since md5 returns alphanumeric only
$_POST['pass'] = stripslashes($_POST['pass']);

// you don't need the next line
$info['password'] = stripslashes($info['password']);

$_POST['pass'] = md5($_POST['pass']);
?>

Link to comment
https://forums.phpfreaks.com/topic/141830-password-issues/#findComment-742578
Share on other sites

I am striplashes from the password entered on the login page. so don't I need to keep this?

$_POST['pass'] = stripslashes($_POST['pass']);

 

I understand I don't need to do that for the password being checked from the DB that has already been when entered in the DB

 

still getting a Incorrect password, please try again. error

Link to comment
https://forums.phpfreaks.com/topic/141830-password-issues/#findComment-742584
Share on other sites

$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);

 

After this portion echo out both $_POST['pass'] and $info['password'] to see if they are blank or have values.

 

Also keep in mind if your column name is "password" MySQL has a habit of turning that into PASSWORD (all caps) since PASSWORD is a function used by the system.

Link to comment
https://forums.phpfreaks.com/topic/141830-password-issues/#findComment-742602
Share on other sites

Well, I'm not sure how you did it when they registered. However, it is not necessary to stripslashes on something that will be encrypted.

 

Give this a shot, I simplified it a bit:

<?php
if (isset($_POST['submit'])) { // if form has been submitted

// makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass'])
	die('You did not fill in a required field.');

// checks it against the database

if (!get_magic_quotes_gpc()) 
	$_POST['email'] = addslashes($_POST['email']);

// Are you sure you meant to do 'username', or was it supposed to be 'email'
$check = mysql_query("SELECT * FROM users WHERE email = '".$_POST['username']."'")or die(mysql_error());

//Gives error if user dosen't exist
if(mysql_num_rows($check)==0)
	die('That is not a vaild username.');

// otherwise, get info
$info = mysql_fetch_assoc($check);

// this isn't needed, unless you did this when they signed up.
// remember, to NOT change $_POST values.
// so we'll setup a new variable, named password
$password = stripslashes($_POST['pass']);

$password = md5($password);

//gives error if the password is wrong

if ($password != $info['password']) {
	$test = 'In the DB: '.$info['password'].'<br />';
	$test.= 'MD5\'d: '.md5($_POST['pass']).'<br />';
	$test.= 'MD5\'d + stripslashes: '.$password.'<br />';
	$test.= 'Do any of these match?';
	echo $test;
               die("Invalid password");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/141830-password-issues/#findComment-742605
Share on other sites

this is what i got

In the DB: 0e9c339f8f5a4c1613eb
MD5'd: 0e9c339f8f5a4c1613ebd4c6284f5658
MD5'd + stripslashes: 0e9c339f8f5a4c1613ebd4c6284f5658
Do any of these match?

 

(this is just a test account so the info above can not be used for anything potentially harmful)

Link to comment
https://forums.phpfreaks.com/topic/141830-password-issues/#findComment-742632
Share on other sites

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.