Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

How to use sticky forms for MD5 passwords?

$
0
0

Hello i wonder how to use sticky forms for password with MD5? If you don't know what sticky forms is i will explain.

 

Explain.

You have a page and your user will register on it. Then the user write wrong in username the username already exists and everything he have wrote stays.

 

I got this problem when i don't use MD5 for passwords it stays but when i use it don't stay there. And there is one more problem I don't get the error messages from $pass1 and $pass2 what would be You forgot to fill the first password field and You forgot to fill the second password field.

 

Would be great if you have a answer for me.

 

 

 

<?php
include 'db.php';


if(isset($_POST['regbutton'])) {

$regfname = "";
$reglname = "";
$regage = "";
$regpass1 = "";
$regpass2 = "";
$regender = "";
$regemail1 = "";
$regemail2 = "";
$regcheckbox = "";
$regpage = "";
$regaccess = "1";
$regdate = date("Y/m/d");

function protect($string){
$string = mysql_real_escape_string($string);
$string = strip_tags($string);
$string = addslashes($string);
return $string;
}

function protectx($stringx){
$stringx = mysql_real_escape_string($stringx);
$stringx = strip_tags($stringx);
$stringx = addslashes($stringx);
$stringx = md5($stringx);
return $stringx;
}

$regfname = protect($_POST['regfname']);
$reglname = protect ($_POST['reglname']);
$regnickname = protect ($_POST['regnickname']);
$regage = protect ($_POST['regage']);
$pass1 = protectx ($_POST['pass1']);
$pass2 = protectx ($_POST['pass2']);
$regender = protect ($_POST['regender']);
$regemail1 = protect ($_POST['regemail1']);
$regemail2 = protect($_POST['regemail2']);
$regpage = protect ($_POST['regpage']);
$regcheckbox = ($_POST['regcheckbox']);
$regip = $_SERVER['REMOTE_ADDR'];

$errors = array();

if($pass1 != $pass2) {

$errors[] = "Passwords don't match.";

}

if($regemail1 != $regemail2) {

$errors[] = "E-Mails don't match";

}

if ($regnickname){
$sql = "SELECT * FROM `accounts` WHERE `nickname`='".$regnickname."'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) > 0){
$errors[] = "Nickname already exist.";
}
}

if ($regemail1){
$sql = "SELECT * FROM `accounts` WHERE `email`='".$regemail1."'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) > 0){
$errors[] = "E-Mail already exist.";
}
}

if ($regemail1) {
$checkregemail1 = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
if(!preg_match($checkregemail1, $regemail1)){
$errors[] = "The E-Mail need to be name@example.com";
}
}

if (!$regcheckbox) {
$errors[] = "You forgot to mark the checkbox";
}

if (!$regfname) {
$errors[] = "You forgot to fill the Firstname field.";
}

if (!$reglname) {
$errors[] = "You forgot to fill the Lastname field.";
}

if (!$regnickname) {
$errors[] = "You forgot to fill the Nickname field.";
}

if (!$regage) {
$errors[] = "You forgot to fill the Age field.";
}

if (!$pass1) {
$errors[] = "You forgot to fill the first password field.";
}

if (!$pass2) {
$errors[] = "You forgot to fill the second password field";
}

if (!$regemail1) {
$errors[] = "You forgot to fill the first E-Mail field.";
}

if (!$regemail2) {
$errors[] = "You forgot to fill the second E-Mail field";
}

if ($regage < 18){
$error[] = "You forgot to fill the Age field";
}


if(count($errors) > 0){
foreach($errors AS $error)
echo $error . "<br>\n";
} else {
mysql_query("INSERT INTO accounts (firstname, lastname, nickname, age, password, gender, email, access, ip, page, date)
values ('$regfname', '$reglname', '$regnickname', '$regage', '$pass1', '$regender', '$regemail1', '$regaccess', '$regip', '$regpage', '$regdate')");
echo "Congratulations the user ";
echo $regnickname ;
echo " has been created and you can ";
echo '<a href="?p=login">login here.</a>';
}
}

echo '
<html><body>
<center><h3>Register</h3>
<form method="post" action="?p=register">
Firstname
<br><input type="text" maxlength="20" name="regfname" value="' . $regfname . '">

<br><br>Lastname
<br><input type="text" maxlength="20" name="reglname" value="' . $reglname . '">

<br><br>Nickname (Max 30 characters)
<br><input type="text" maxlength="30" name="regnickname" value="' . $regnickname . '">

<br><br>How old are you?
<br><input type="text" maxlength="3" name="regage" value="' . $regage . '">

<br><br>Password (Max 15 characters)
<br><input type="password" maxlength="15" name="pass1">

<br><br>Password again (Max 15 characters)
<br><input type="password" maxlength="15" name="pass2">

<br><br>Man or Woman?<br>
<select name="regender" value="' . $regender . '"> <option>Man</option><option>Woman</option></select>

<br><br>Email
<br><input type="text" name="regemail1" value="' . $regemail1 . '">

<br><br>Email again
<br><input type="text" name="regemail2" value="' . $regemail2 . '">

<br><br>Do you got a homepage? Maybe facebook?<br>
<input type="text" name="regpage" value="' . $regpage . '"><br><br>

I have read the <a href="?p=rules">RULES </a>and I agree them.
<input type="checkbox" name="regcheckbox" ' . (isset($_POST['regcheckbox']) ? 'checked="checked"':'') .'><br><br>

<input type="submit" name="regbutton" value="Register">
</form>
</center>
</html></body>';
?>
 

Viewing all articles
Browse latest Browse all 13200

Trending Articles