Jump to content

Password requirements


YNWA

Recommended Posts

I have my password setup in the registration form, it all works fine.

 

However I am looking to max requirements for those who register.

 

Things such as:

 

Valid Email address, as you can enter anything at the minute and it will register it as your username and email address, but I want something like having the '@' as a requirement.

 

Passwords, havin a requirement that it must be minimum characters of 5, have at least 1 number in etc...

 

Anyone help me out?

 

heres my form code:

 

<script>
function validate()
{

var email = document.getElementById("userEmail").value;

    if ((email == null) || (email == ""))
    {
    window.alert("Please Insert a Valid Email Address");
    return false;
    }
    else
    {
    
var password = document.getElementById("userPassword").value;

            if ((password == null) || (password == ""))
            {
            window.alert("Please Insert a Valid Password");
            return false;
            }
            else
            {
            
var passwordconfirm = document.getElementById("userConfirmPassword").value;

            if ((password) != (passwordconfirm)) 
					{
                        alert("Passwords do not match!");
                        form1.userPassword.focus();
                        return false;
                        }
                        else
                        {

var firstname = document.getElementById("userFName").value;

                                    if ((firstname == null) || (firstname == ""))
                                    {
                                    window.alert("Please Insert a Valid First Name");
                                    return false;
                                    }
                                    else
                                    {

var surname = document.getElementById("userSName").value;

                                        if ((surname == null) || (surname == ""))
                                        {
                                        window.alert("Please Insert a Valid Surname");
                                        return false;
                                        }
                                    }
                                
                        }            
            }                  
    }         
}
</script>
</head>


<?php

if ($_POST[op] != "yes")
{
	echo "<h2><font face='arial' size='2' align='center'></h2>
	<p>
		Please enter your details below:
	</p>";

display_form();



}
else
{


//  Create a connection with the SQL server
$conn = mysql_connect("localhost", "root", "");

mysql_select_db("will",$conn);

$sql = "INSERT INTO registration VALUES 
(
'$_POST[userEmail]',
'$_POST[userPassword]',
'$_POST[userFName]',
'$_POST[userSName]'
)";


$user = $_POST[userEmail];	
$checkuser = "SELECT userEmail FROM registration WHERE userEmail = '$user'";

$result = mysql_query($checkuser,$conn);											//  Execute the sql

$record = mysql_num_rows($result);												//  Does record exist?
if ($record != 0)
{
	echo "<p>User Email <b> $_POST[userEmail] </b> already exists, please choose another </p>";		//  If it does, tell the user

display_form($_POST[userFName],$_POST[userSName],$_POST[userPassword],$_POST[userConfirmPassword]);		//  Ask for details again
}
else
{

if (mysql_query($sql,$conn))													//  Execute the SQL
	{
	echo "User Details Added! <br />";
	echo "Thank you for registering!";

	}		

	else
	{
	echo "Error, User Details Not Added, please check details and try again!<br />";

	}
}
}

function display_form($userFName="", $userSName="", $userPassword="", $userConfirmPassword="", $user="")
{

$display = "<form id=\"form1\" name=\"form1\" method=\"post\" onSubmit=\"return validate($_POST)\" action=\"$SERVER[php_SELF]\">

<table width=\"322\" border=\"0\">
  <tr>
    <td width=\"147\">User Email</td>
    <td width=\"159\"><label>
      <input type=\"text\" name=\"userEmail\" id=\"userEmail\" value=\"\" />
    </label></td>
  </tr>
  <tr>
    <td>Forename</td>
    <td><label>
      <input type=\"text\" name=\"userFName\" id=\"userFName\" value=\"$userFName\" />
    </label></td>
  </tr>
  <tr>
    <td>Surname</td>
    <td><label>
      <input type=\"text\" name=\"userSName\" id=\"userSName\" value=\"$userSName\" />
    </label></td>
  </tr>
  <tr>
    <td>Password</td>
    <td><label>
      <input type=\"password\" name=\"userPassword\" id=\"userPassword\" value=\"$userPassword\" />
    </label></td>
  </tr>
  <tr>
    <td>Confirm Password </td>
    <td><label>
      <input type=\"password\" name=\"userConfirmPassword\" id=\"userConfirmPassword\" value=\"$userConfirmPassword\"  />
    </label></td>
  </tr>

</table>
  	<input type=\"hidden\" name=\"op\" value=\"yes\">
	<input type=\"submit\" name=\"submit\" value=\"Submit\">
	<input type=\"reset\" name=\"reset\" value=\"Reset\">
</form>";
echo $display;

 

Cheers in advance ;)

Link to comment
https://forums.phpfreaks.com/topic/94882-password-requirements/
Share on other sites

Seriously I aint got a clue, this PHP is too much for me.

 

Anyone have a definate answer for me? On where to put it?

 

 

You could take a stab at it and through it in your validation function perhabs since you want to "validate" the email, but this php stuff is just way over my head so I have no clue

Link to comment
https://forums.phpfreaks.com/topic/94882-password-requirements/#findComment-486044
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.