Jump to content

Recommended Posts

Hey All,

 

I am trying to figuere out how to apply MD5 to my password field for my user setup.

this  was my setup I ran

<?php
include_once 'tbnl-functions.php';
echo '<h3>Setting up</h3>';
createTable('tbnlmembers', 
'id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
user VARCHAR(16), pass VARCHAR(16), fname VARCHAR(16), lname VARCHAR(16), email VARCHAR(16),
INDEX(user(6))');
createTable('tbnlmessages',
'id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
auth VARCHAR(16), recip VARCHAR(16), pm CHAR(1),
time INT UNSIGNED, message VARCHAR(4096),
INDEX(auth(6)), INDEX(recip(6))');
createTable('tbnlfriends', 'user VARCHAR(16), friend VARCHAR(16),
INDEX(user(6)), INDEX(friend(6))');
createTable('tbnlprofiles', 'user VARCHAR(16), text VARCHAR(4096),
INDEX(user(6))');
?>

 

and here is my signup page

 

<?php
$sheet_name = "users-signup";
include ("../inc/control.php"); //main inc dir.
include ("inc/tbnl-functions.php"); //users inc dir.
include ("inc/tbnl-header.php");
include ("../inc/page-top.php");
echo $content;
echo <<< _END
<script>
function checkUser(user)
{
if (user.value == '')
{
document.getElementById('info').innerHTML = ''
return
}
params = "user=" + user.value
request = new ajaxRequest()
request.open("POST", "inc/tbnl-checkuser.php", true)
request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded")
request.setRequestHeader("Content-length", params.length)
request.setRequestHeader("Connection", "close")
request.onreadystatechange = function()
{
if (this.readyState == 4)
{
if (this.status == 200)
{
if (this.responseText != null)
{
document.getElementById('info').innerHTML =
this.responseText
}
else alert("Ajax error: No data received")
}
else alert( "Ajax error: " + this.statusText)
}
}
request.send(params)
}
function ajaxRequest()
{
try
{
var request = new XMLHttpRequest()
}
catch(e1)
{
try
{
request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e2)
{
try
{
request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch(e3)
{
request = false
}
}
}
return request
}
</script>
<h3>Sign up Form</h3>
_END;
$error = $user = $pass = "";
if (isset($_SESSION['user']))
    destroySession();
if (isset($_POST['user'])) {
    $user = sanitizeString($_POST['user']);
    $pass = sanitizeString($_POST['pass']);
    $fname = sanitizeString($_POST['fname']);
    $lname = sanitizeString($_POST['lname']);
    $email = sanitizeString($_POST['email']);
    if ($user == "" || $pass == "") {
        $error = "Not all fields were entered<br /><br />";
    } else {
        $query = "SELECT * FROM tbnlmembers WHERE user='$user'";
        if (mysql_num_rows(queryMysql($query))) {
            $error = "That username already exists<br /><br />";
        } else {
            $query = "INSERT INTO tbnlmembers VALUES(NULL, '$user', '$pass', '$fname', '$lname', '$email')";
            queryMysql($query);
        }
        header('Location: http://tbaynightlife.com/users/tbnl-login.php');
        die("");
    }
}
    echo <<< _END
<div id="user-sign-up-form">
	<form method='post' action='tbnl-signup.php'>$error
		<ul class="single">
			<li><label>First Name</label><input type='text' maxlength='16' name='fname' value='$fname' /></li>
			<li><label>Last Name</label><input type='text' maxlength='16' name='lname' value='$lname' /></li>
			<li><label>Desired Login Name</label><input type='text' maxlength='16' name='user' value='$user' onBlur='checkUser(this)'/><br /><label> </label><span id='info'></span></li>
			<li><label>Password</label><input type='text' maxlength='16' name='pass' value='$pass' /></li>
			<li><label>Email</label><input type='text' maxlength='16' name='email' value='$email' /></li>
			<li><input type='submit' value='Signup' /></li>
		</ul>
	</form>
</div>
_END;
    include ("../inc/page-bot.php");
?>

 

I tried looking around, but im not understanding where to apply md5, do i need to write a function? or can i do it upon setup of my table?

 

thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/172146-help-with-md5-where-to-apply/
Share on other sites

pass VARCHAR(16) to pass VARCHAR(32)

 

register:

INSERT INTO tbnlmembers VALUES(NULL, '$user', MD5('$pass'), '$fname', '$lname', '$email')

 

login:

SELECT * FROM tbnlmembers WHERE username = $username AND pass = MD5('$pass')

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.