паролите дали са кратки или дълги

chaser

Registered
Как да си направя така че като си напиша някаква парола да да пише да ли е кратка средна или голяма и да не се въвеждат по-малко от 6 символа ето и системата за регистер
Код:
<?php 
ob_start(); 
// allows you to use cookies 
include("conf.php"); 
//gets the config page 
if ($_POST[register]) { 
// the above line checks to see if the html form has been submitted 
$username = $_POST[username]; 
$password = $_POST[pass]; 
$cpassword = $_POST[cpass]; 
$email = $_POST[emai1]; 

$duljina =  strlen($username); 

//the above lines set variables with the user submitted information 
if($username==NULL|$password==NULL|$cpassword==NULL|$email==NULL) { 
//checks to make sure no fields were left blank 
echo "A field was left blank."; 
}else{ 
//none were left blank! We continue... 
if($password != $cpassword) { 
// the passwords are not the same! 
echo "Passwords do not match"; 
} 
else if ($duljina < 6) { 

echo "Въведете по-дълго username"; 

}else{ 
// the passwords are the same! we continue... 
$password = md5($password); 
// encrypts the password 
$checkname = mysql_query("SELECT username FROM users WHERE username='$username'"); 
$checkname= mysql_num_rows($checkname); 
$checkemail = mysql_query("SELECT email FROM users WHERE email='$email'"); 
$checkemail = mysql_num_rows($checkemail); 
if ($checkemail>0|$checkname>0) { 
// oops...someone has already registered with that username or email! 
echo "The username or email is already in use"; 
}else{ 
// noone is using that email or username! We continue... 
$username = htmlspecialchars($username); 
$password = htmlspecialchars($password); 
$email = htmlspecialchars($email); 
// the above lines make it so that there is no html in the user submitted information. 
//Everything seems good, lets insert. 
$query = mysql_query("INSERT INTO users (username, password, email,avatar) VALUES('$username','$password','$email','$avatar')"); 
// inserts the information into the database. 
echo "Акаунта е създаден успешно!"; 
} 
} 
} 
} 
else 
{ 
// the form has not been submitted...so now we display it. 
echo (" 
  

<div class='login'> 
<form  method='POST'> 
<table class='lista' style='width:600px;' align='center' cellspacing='2' cellpadding='5'> 
<tr> 
<td class='header' align='center' colspan='2'>Създай нов акаунт</td> 
</tr> 
<tr> 
<td class='lista' align='right' width='40%'>Потребителско име:</td> 
<td class='lista'><input type=\"text\"  maxlength=\"25\" name=\"username\"  id=\"txt1\" onkeyup=\"showHint(this.value)\"/><br />
<p><font size='2pt'>Потребителското име трябва да бъде не по-малко от 6 букви.</font></p></td> 
<p><span id='txtHint'></span></p>
</tr> 
<tr> 
<td class='lista' align='right'>Парола:</td> 
<td class='lista'><input type='password' name='pass'></td> 
</tr> 
<tr> 
<td class='lista' align='right'>Повтори паролата:</td> 
<td class='lista'><input type='password' name='cpass'></td> 
</tr> 
<tr> 
<td class='lista' align='right'>Email адрес:</td> 
<td class='lista'><input type='text' name='emai1'></td> 
</tr> 
<tr> 
<td class='lista' align='right'> </td> 
<td class='lista'><input type='submit' name='register' value='Регистрирай ме!'></td> 
</tr> 
</table> 
</form> 
</div> 
"); 
} 
?> 
<meta http-equiv="ContentType" content="text/html; charset=windows-1251" /> 
<script language="javascript"> 
var xmlhttp 

function showHint(str) 
{ 
if (str.length==0) 
{ 
document.getElementById("txtHint").innerHTML=""; 
return; 
} 
xmlhttp=GetXmlHttpObject(); 
if (xmlhttp==null) 
{ 
alert ("Your browser does not support XMLHTTP!"); 
return; 
} 
var url="gethint.php"; 
url=url+"?q="+str; 
url=url+"&sid="+Math.random(); 
xmlhttp.onreadystatechange=stateChanged; 
xmlhttp.open("GET",url,true); 
xmlhttp.send(null); 
} 

function stateChanged() 
{ 
if (xmlhttp.readyState==4) 
{ 
document.getElementById("txtHint").innerHTML=xmlhttp.responseText; 
} 
} 

function GetXmlHttpObject() 
{ 
if (window.XMLHttpRequest) 
{ 
// code for IE7+, Firefox, Chrome, Opera, Safari 
return new XMLHttpRequest(); 
} 
if (window.ActiveXObject) 
{ 
// code for IE6, IE5 
return new ActiveXObject("Microsoft.XMLHTTP"); 
} 
return null; 
} 
</script> 
<link rel='stylesheet' type='text/css' href='style/web.css'/> 
<link rel='stylesheet' type='text/css' href='style/login.css'/>
 
<?php
ob_start();
// allows you to use cookies
include("conf.php");
//gets the config page
if ($_POST[register]) {
// the above line checks to see if the html form has been submitted
$username = $_POST[username];
$password = $_POST[pass];
$cpassword = $_POST[cpass];
$email = $_POST[emai1];

$duljinauser = strlen($username);
$duljinapass = strlen($password);

//the above lines set variables with the user submitted information
if($username==NULL|$password==NULL|$cpassword==NULL|$email==NULL) {
//checks to make sure no fields were left blank
echo "A field was left blank.";
}else{
//none were left blank! We continue...
if($password != $cpassword) {
// the passwords are not the same!
echo "Passwords do not match";
}
else if ($duljinauser < 6) {

echo "Въведете по-дълго username";

} else if ($duljinapass < 6) {
echo "Изберете по-дълга парола" ;
}
else{
// the passwords are the same! we continue...
$password = md5($password);
// encrypts the password
$checkname = mysql_query("SELECT username FROM users WHERE username='$username'");
$checkname= mysql_num_rows($checkname);
$checkemail = mysql_query("SELECT email FROM users WHERE email='$email'");
$checkemail = mysql_num_rows($checkemail);
if ($checkemail>0|$checkname>0) {
// oops...someone has already registered with that username or email!
echo "The username or email is already in use";
}else{
// noone is using that email or username! We continue...
$username = htmlspecialchars($username);
$password = htmlspecialchars($password);
$email = htmlspecialchars($email);
// the above lines make it so that there is no html in the user submitted information.
//Everything seems good, lets insert.
$query = mysql_query("INSERT INTO users (username, password, email,avatar) VALUES('$username','$password','$email','$avatar')");
// inserts the information into the database.
echo "Акаунта е създаден успешно!";
}
}
}
}
else
{
// the form has not been submitted...so now we display it.
echo ("


<div class='login'>
<form method='POST'>
<table class='lista' style='width:600px;' align='center' cellspacing='2' cellpadding='5'>
<tr>
<td class='header' align='center' colspan='2'>Създай нов акаунт</td>
</tr>
<tr>
<td class='lista' align='right' width='40%'>Потребителско име:</td>
<td class='lista'><input type=\"text\" maxlength=\"25\" name=\"username\" id=\"txt1\" onkeyup=\"showHint(this.value)\"/><br />
<p><font size='2pt'>Потребителското име трябва да бъде не по-малко от 6 букви.</font></p></td>
<p><span id='txtHint'></span></p>
</tr>
<tr>
<td class='lista' align='right'>Парола:</td>
<td class='lista'><input type='password' name='pass' onkeyup='passwordStrength(this.value)' ></td>
</tr>
<tr>
<td class='lista' align='right'>Повтори паролата:</td>
<td class='lista'><input type='password' name='cpass'></td>
<td class='lista'> <div id="passwordDescription">Password not entered</div>

<div id="passwordStrength" class="strength0"></div></td>
</tr>
<tr>
<td class='lista' align='right'>Email адрес:</td>
<td class='lista'><input type='text' name='emai1'></td>
</tr>
<tr>
<td class='lista' align='right'> </td>
<td class='lista'><input type='submit' name='register' value='Регистрирай ме!'></td>
</tr>
</table>
</form>
</div>
");
}
?>
<meta http-equiv="ContentType" content="text/html; charset=windows-1251" />
<script language="javascript">

function passwordStrength(password)

{

var desc = new Array();

desc[0] = "Very Weak";

desc[1] = "Weak";

desc[2] = "Better";

desc[3] = "Medium";

desc[4] = "Strong";

desc[5] = "Strongest";



var score = 0;



//if password bigger than 6 give 1 point

if (password.length > 6) score++;



//if password has both lower and uppercase characters give 1 point

if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;



//if password has at least one number give 1 point

if (password.match(/\d+/)) score++;



//if password has at least one special caracther give 1 point

if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) score++;



//if password bigger than 12 give another 1 point

if (password.length > 12) score++;



document.getElementById("passwordDescription").innerHTML = desc[score];

document.getElementById("passwordStrength").className = "strength" + score;

}

</script>
<style>
#passwordStrength

{

height:10px;

display:block;

float:left;

}



.strength0

{

width:250px;

background:#cccccc;

}



.strength1

{

width:50px;

background:#ff0000;

}



.strength2

{

width:100px;

background:#ff5f5f;

}



.strength3

{

width:150px;

background:#56e500;

}



.strength4

{

background:#4dcd00;

width:200px;

}



.strength5

{

background:#399800;

width:250px;

}
</style>
<script language="javascript">
var xmlhttp

function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
var url="gethint.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
</script>
<link rel='stylesheet' type='text/css' href='style/web.css'/>
<link rel='stylesheet' type='text/css' href='style/login.css'/>[/code]

Я пробвай така дали ще стане ?
 

Back
Горе