TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 12-11-2008, 12:02 PM   #1 (permalink)
The Contributor
 
Normo's Avatar
 
Join Date: Oct 2008
Location: UK
Posts: 30
Thanks: 0
Normo is on a distinguished road
Default Password Hashing

Hey I'm having some problems with hashing passwords into a database and then comparing them to a user input.

Here's my code:
PHP Code:
if(isset($_REQUEST['username'])){
session_start();
$con mysql_connect("localhost","","") or die('Could not connect: ' mysql_error());

mysql_select_db("normo_mydb") or die(mysql_error());


$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = md5($_POST['password']);
$result mysql_query("SELECT Password FROM Users WHERE Username = '$username'");
$row mysql_fetch_array($result);
$num mysql_num_rows($result);

if(
$num != "0" && $password == $row['Password']) {
header('location:new.php');
}
else {
session_unset();
session_destroy();
}

mysql_close($con);
}
if(isset(
$_REQUEST['userReg'])){
session_start();
$con mysql_connect("localhost","","") or die('Could not connect: ' mysql_error());

mysql_select_db("normo_mydb") or die(mysql_error());

$_SESSION['userReg'] = $_POST['userReg'];
$_SESSION['passReg'] = md5($_POST['passReg']);
$sql mysql_query("INSERT INTO Users
(Username, Password) VALUES('
$userReg','$passReg')") or die(mysql_error());
echo 
"You are now registered!";

mysql_close($con);

I have the script running fine without hashing the passwords, just when I add the MD5 function it goes wrong.

I do manage to hash the password into the database but it doesn't work when the user logs in.

Also it doesn't hash the password every time. Sometimes it just enters the password as plain text into the database.

Any help would be appreciated. :)
Normo is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loggining ( password and encryption ) Orc General 9 02-09-2008 08:24 AM
Password generator Rizza Script Giveaway 6 12-11-2007 05:04 AM
Single way password storage DragonBe General 3 11-21-2007 01:42 PM
Forgot Password Gurnk MySQL & Databases 8 11-20-2007 04:06 PM


All times are GMT. The time now is 06:40 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design