Jump to content

Recommended Posts

Hi all,

'Hope it is ok to post this here'

 

I have a simple login form and registration that connects to table on database.

everything worked and I decided to add md5 to my password to protect it a bit.

 

When I 'Register' the md5 password $_POST to table in DB stay the same. i.e. [username]John [password]123 (md5: 5f77gj8vg2903nj38)

and the same for

[username]Jill [password]abc (md5: 5f77gj8vg2903nj38)

 

Register.php  - Form

<form action="registrar.php" method="POST">
    <p><label>Username:</label> <input type="text" name="username" style="width:200px;" ></p>
    <p><label>Password:</label> <input type="password" name="password" style="width:200px;" ></p>
    <p><label>Email:</label>
<input type="text" name="email" style="width:200px;" ></p>
<p><input type="submit" value="Register" class="sub_but">
<input class="sub_but" type="reset" value="Reset" ></p>
</form>

 

registrar.php - Processor

 

<?php

 

$host="localhost";

$username="username";

$password="password";

$db_name="database";

$tbl_name="members";

 

// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DATABASE");

 

$wagwoord = md5("password"); //this is what I added

//Collect user information

$username = $_POST['username'];

$password = (md5($_POST['password']) == $wagwoord); //previous: $password = $_POST['password']

$email = $_POST['email'];

 

//Write to table the user information

mysql_query("INSERT INTO members (username, password, email) VALUES ('$username', '$wagwoord', '$email')") //previous $password

 

?>

<html>

  <head></head>

  <body>

  <p>Thank you. Your Registration was Successfull. Please <span class="red">login</span> below.</p>

  <iframe src="login.php"></iframe>

  </body>

  </html>

 

I have a problem to read/get value of the MD5 password as well. I basically used the same method.

 

Any help appreciated

 

Link to comment
https://forums.phpfreaks.com/topic/219053-md5/
Share on other sites

[edit]

Gah... too sleepy

 

$wagwoord = md5("password"); //this is what I added 

 

should be

 

$wagwoord = md5($_POST['password']); //this is what I added 

 

also make sure a field in database is able to store at least 32 characters (that's how long MD5 hashes are)

Link to comment
https://forums.phpfreaks.com/topic/219053-md5/#findComment-1135970
Share on other sites

Did I tell you to use $_POST['mypassword']? I guess not. The field in your form has name="password" so you need to use $_POST['password']

 

<?php
//connct to database...

$password = md5($_POST['password']);
$username = mysql_real_escape_string($_POST['username']);
$email= mysql_real_escape_string($_POST['email']);

mysql_query("INSERT INTO members (username, password, email) VALUES ('$username', '$password', '$email')");

Link to comment
https://forums.phpfreaks.com/topic/219053-md5/#findComment-1135974
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.