Forum Moderators: coopster

Message Too Old, No Replies

php mysql data !=

Cannot get password to match stored Pw

         

dmehta

3:20 am on May 12, 2009 (gmt 0)

10+ Year Member



Hello ,
I'm new to php , I have a form with an input box in a which accepts a password , i am trying some code which matches the entered password to one which is stored in a mysql DB , somehow my "if else" code below is always returning false . I have tried changing the field type in the Db but still no luck need help with the code

The following is the code i'm using to test

$password=$_POST["password"];
$password = test($password);
$password= md5($password);

// basic injection check

function test($password)
{
$magic_quotes_active = get_magic_quotes_gpc() ;
$new_php_version = function_exists("mysql_real_escape_string") ; // php version >= 4.3.0

if($new_php_version){ // if new php version undo magic quotes

if($magic_quotes_active){ $password= stripslashes($password);}

$password= mysql_real_escape_string($password);
}
else { // version is older than 4.3.0

if(!$magic_quotes_active){$value=addslashes($value);} //check if magic quotes is not active then manually add slashes
}
return $password ;
}

// Here we check the the form password with the database one

checkpassword($password);

function checkpassword($password){
$query = ("SELECT `pass` , `station` FROM `check` ");
$answer = mysql_query($query) or die("Query Failed".mysql_error());

$result = mysql_fetch_array($answer);

if ( $result[0] != $password ){
echo ("Check Password"."<br/>");

} else{
echo("All OK"."<br/>");

}

// Next we just print them out to check visually

echo ( "PASSWORD = " .$password ."<br/>". "result = ".$result[0]."<br/>". "station = ".$result[1]."<br/>") ;

}

dmehta

2:11 pm on May 12, 2009 (gmt 0)

10+ Year Member



Solved ...thanks if anyone was considering a reply

eelixduppy

3:11 pm on May 12, 2009 (gmt 0)



Glad you were able to resolve your issue. :)

..and Welcome to WebmasterWorld!

dmehta

7:28 pm on May 12, 2009 (gmt 0)

10+ Year Member



thank you

nanat

7:36 am on May 13, 2009 (gmt 0)

10+ Year Member



Good on u solve it ..