Forums

PHP

This topic is locked

crypt

Posted 20 May 2003 04:09:02
1
has voted
20 May 2003 04:09:02 Dean Blackborough posted:
Annoying problem with Crypt.

Working through a tutorial to build an Admin login system from DMX PHP Web Development. I have managed to encrypt the password on the add user page but now when trying to check the encryted password I keep getting username password do not match.

Is there anything wrong with these two snippets.

<pre id=code><font face=courier size=2 id=code>$user = $form_data['Username'];
$password = $form_data['Password'];</font id=code></pre id=code>

<pre id=code><font face=courier size=2 id=code>$myquery = "SELECT * FROM tblusers WHERE Password = '" . crypt($password,"DWMXPHP" . "'";</font id=code></pre id=code>

Whole thing fine if I replace crypt($password,"DWMXPHP" with $password and just enter the encrypted password.

I am using the same key to encrypt each time, this is really starting to annoy me now <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

--------------------------------------
www.galleryof3d.com
(PHP and MySQL)

Replies

Replied 20 May 2003 07:38:58
20 May 2003 07:38:58 Allan Kent replied:
hey,

can you post the code for adding a user as well?

thanks
Replied 20 May 2003 14:49:57
20 May 2003 14:49:57 Dean Blackborough replied:
Ok here is some of the code for adding a user.

// Setup data to insert
$name = $formdata['Name'];
$username = $formdata['Username'];
$password = $formdata['Password'];
$status = $formdata['Status'];

// Encrypt the password using the key "DWMXPHP"
$password = crypt($password,"DWMXPHP";

// Connect to mySQL server
$mysql = mysql_connect($myhost, $myuser, $mypass);
if (!$mysql) {
$error = "Cannot connect to mySQL server";
return($error);
}

// Connect to Database
$mysqldb = mysql_select_db($mydb, $mysql);
if (!$mysqldb) {
$error = "Cannot open Database";
return($error);
}

// Insert Data
$myquery = "INSERT INTO tblusers (Name, Username, Password, Status) VALUES ('$name', '$username', '$password', '$status')";
$result = mysql_query($myquery, $mysql);
if (!$result) {
$error = "Cannot run Query";
return $error;
}

--------------------------------------
www.galleryof3d.com
(PHP and MySQL)
Replied 20 May 2003 16:29:58
20 May 2003 16:29:58 Dean Blackborough replied:
DOH!!

Worked it out, the code is fine, my password field on my databese was limited to 10 characters so the full encrypted password wasn't being stored.

DOH!

Cheers allankent, made me look at the add_users page which helped after browsing the php manual.

--------------------------------------
www.galleryof3d.com
(PHP and MySQL)
Replied 20 May 2003 17:30:40
20 May 2003 17:30:40 Allan Kent replied:
heh, yeah, ive nuked myself like that a few times as well.

allan

Reply to this topic