PDA

View Full Version : reading MD5 password in php


Lionel
01-10-2002, 03:50 AM
I found a free simple classifieds software that I would like to use with VB. Problem is, it is using a password text instead of MD5. I was able to encrypt the MD5 at registration. Now I have to be able to read it at login and set the cookie to be vb's cookie. Once I do that, then I can use VB login system.

How can I alter the below function to read MD5 instead of text?
I am also including portion of the login and setcookie of that other software

Function

function verifyUser()
{
global $ADMIN_EMAIL;
session_start();
global $email, $passwd;
if( session_is_registered( "email" ) && session_is_registered( "passwd" ) )
{
$result = mysql_query( "SELECT email, passwd FROM user WHERE email='$email' AND passwd LIKE BINARY '$passwd'" ) or error( "Login failed, please contact <a href=\"$ADMIN_EMAIL\">adminstrator</a>" );
if( mysql_num_rows( $result ) == 1 ) return true;
}
return false;
}
function verifyAdmin()
{
session_start();
global $ADMIN_NAME, $ADMIN_PASS, $adminPasswd, $adminName;
if( session_is_registered( "adminName" ) && session_is_registered( "adminPasswd" ) )
{
if( $adminName == $ADMIN_NAME && $adminPasswd == $ADMIN_PASS )
return true;
}
return false;
}



login.php

if( $action == "login" )
{
$email = trim( $email );
$passwd = trim( $passwd );
if( $email == "" ) error( "Please enter your e-mail" );
if( $passwd == "" ) error( "Please enter your password" );

dbConnect();
$result = mysql_query( "SELECT email FROM user WHERE email='$email'" ) or error( mysql_error() );
if( mysql_num_rows( $result ) != 1 ) error( "Sorry, e-mail doesn't exist" );
$result = mysql_query( "SELECT email FROM user WHERE email='$email' AND passwd LIKE BINARY '$passwd'" ) or error( mysql_error() );
if( mysql_num_rows( $result ) != 1 ) error( "Sorry, invalid password" );
else
{
session_register( "email" );
session_register( "passwd" );
setcookie( "email", $email, time()+3600*24*365 );
if( isset( $cat ) ) header( "Location: ./list.php?cat=$cat" );
if( $cat == "" ) header( "Location: ./account.php" );
}
}

}

Admin
01-10-2002, 09:33 AM
Function

function verifyUser()
{
global $ADMIN_EMAIL;
session_start();
global $email, $passwd;
if( session_is_registered( "email" ) && session_is_registered( "passwd" ) )
{
$result = mysql_query( "SELECT email, passwd FROM user WHERE email='$email' AND passwd LIKE BINARY '".md5($passwd)."'" ) or error( "Login failed, please contact <a href=\"$ADMIN_EMAIL\">adminstrator</a>" );
if( mysql_num_rows( $result ) == 1 ) return true;
}
return false;
}
function verifyAdmin()
{
session_start();
global $ADMIN_NAME, $ADMIN_PASS, $adminPasswd, $adminName;
if( session_is_registered( "adminName" ) && session_is_registered( "adminPasswd" ) )
{
if( $adminName == $ADMIN_NAME && $adminPasswd == $ADMIN_PASS )
return true;
}
return false;
}

login.php

if( $action == "login" )
{
$email = trim( $email );
$passwd = trim( $passwd );
if( $email == "" ) error( "Please enter your e-mail" );
if( $passwd == "" ) error( "Please enter your password" );

dbConnect();
$result = mysql_query( "SELECT email FROM user WHERE email='$email'" ) or error( mysql_error() );
if( mysql_num_rows( $result ) != 1 ) error( "Sorry, e-mail doesn't exist" );
$result = mysql_query( "SELECT email FROM user WHERE email='$email' AND passwd LIKE BINARY '".md5($passwd)."'" ) or error( mysql_error() );
if( mysql_num_rows( $result ) != 1 ) error( "Sorry, invalid password" );
else
{
session_register( "email" );
session_register( "passwd" );
setcookie( "email", $email, time()+3600*24*365 );
if( isset( $cat ) ) header( "Location: ./list.php?cat=$cat" );
if( $cat == "" ) header( "Location: ./account.php" );
}
}

}

Lionel
01-10-2002, 10:56 AM
login.php does not let me in...

Admin
01-10-2002, 01:09 PM
Are you sure the passwords are really encrypted in the database?
Make sure that your password is (maybe only the newer passwords are and not all of them).

Lionel
01-10-2002, 01:23 PM
they are. Anyway I got around it by leaving it as is and parse bbuserinfo[username] and bbuserinfo[password] just like you helped with the other album code. I made it such a way that I removed all login info, switch registration to VB form, updates that database from register.php and member.php. Then in welcometext template I placed the links. As a result, non members can view albums (if not private or if provided password to view) and ads from main menu, members access their controls to manipulate private albums and ads by parsing the required info directly from the welcometext. The whole thing is nice. I have not put up the ads yet because it requires gd which I installed, but am afraid to recompile php so I do not mess up site which got a lot of traffic.

I saw your answer at .com in the html section and I am going to try it in the usercpnav. There I had simulated it with a transparent gif but it bothered my eyes a little because it was not aligning with other menuitems.

Thanks for all help!