Skip to content

Instantly share code, notes, and snippets.

@abdualrhman1410
Created November 30, 2012 21:40
Show Gist options
  • Save abdualrhman1410/4178871 to your computer and use it in GitHub Desktop.
Save abdualrhman1410/4178871 to your computer and use it in GitHub Desktop.
<?
include 'connection.php';
$username= $_POST['username'];
$query=mysql_query("SELECT username from users where username='$username'");
$num= mysql_num_rows($query);
if($_POST['username']){
if($num != 0)
echo $i=1;
else{
echo $i=0;
}
}elseif($_POST['email']){
$email=$_POST['email'];
$quermail=mysql_query("SELECT email from users where email='$email'");
$nummail=mysql_num_rows($quermail);
if($nummail !=0){
echo $i="exist";
}else{
echo "not_exist";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" >
var checkpassword;
var checkusername;
var checkemail;
function warning(class_id,color,text,outputid){
$(class_id).css("background",color);
$(outputid).text(text);
$(outputid).css('color',color);
}
function checkStrength(password){
//initial strength
var strength = 0
//if the password length is less than 6, return message.
if (password.length < 6) {
$('#result').removeClass();
$('#result').addClass('short');
return 'Too short'
}
//length is ok, lets continue.
//if length is 8 characters or more, increase strength value
if (password.length > 6){ strength += 1; checkpassword=true;}
//if password contains both lower and uppercase characters, increase strength value
if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) strength += 1
//if it has numbers and characters, increase strength value
if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) strength += 1
//if it has one special character, increase strength value
if (password.match(/([!,%,&,@,#,$,^,*,?,_,~])/)) strength += 1;
//if it has two special characters, increase strength value
if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,",%,&,@,#,$,^,*,?,_,~])/)) strength += 1;
//now we have calculated strength value, we can return messages
//if value is less than 2
if (strength < 2 ) {
$('#resulte_password').removeClass()
$('#resulte_password').addClass('weak')
return 'Weak'
} else if (strength == 2 ) {
$('#resulte_password').removeClass()
$('#resulte_password').addClass('good')
return 'Good'
} else {
$('#resulte_password').removeClass()
$('#resulte_password').addClass('strong')
return 'Strong'
}
}
$(document).ready(function(){
var username=$("#username").val();
var password=$(".password").val();
var email=$(".email").val();
$('#username').focusout(function(){
// begin check username
var username=$("#username").val();
var spilt=username.split(' ').length;
if(spilt >1 ){
warning("#username","red","اسم المستخدم يحتوي على مسافات","#resulte");
}else if (username=="" ){
warning("#username","red","المدخل فارغ","#resulte");
}else if (username.length <3){
warning("#username","red","اسم المستخدم قصير جدا","#resulte");
}
else{
$.post('check_data2.php',{ username: create_user.username.value});
$.post('check_data.php',{username: create_user.username.value},function(output){
if(output ==1){
warning("#username","red","اسم المستخدم مسجل ","#resulte");
}
else{
warning("#username",'green','مُتاح','#resulte');
checkusername=true;
}
});
}
});
//end check username
$('.password').keyup(function(){
// begin check password
var password=$(".password").val();
$('#resulte_password').html(checkStrength(password));
// end check password
}); // begin check email
$('.email').focusout(function(){
var email=$(".email").val();
var atpos=email.indexOf("@");
var dotpos=email.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
{
warning(".email","red","الرجاء ادخال العنوان صحيح","#resulte_email");
}else{
$.post('check_data.php',{ email : $('.email').val() },function(output){
if(output =="exist"){
warning(".email","red","هذا الايميل مستخدم","#resulte_email");
}else{
warning(".email","green","متاح","#resulte_email");
checkemail=true;
}
}
);
}
});
$('.create_user').submit(function(){
if(checkpassword != true || checkusername !=true ){
return false;
}
if(checkemail !=true) return false;
});
});
</script>
<style type="text/css">
.user{
background: #ccc112;
}
</style>
</head>
<body>
<form method="post" name="create_user" class="create_user" action="creatAcc.php">
username: <input type="text" name="username" id="username" /><i id="resulte">user name must be not have space</i>
<Br>
password: <input type="password" name="passowrd" class="password" /><i id="resulte_password"></i>
<br>
email : <input type="text" name="email" class="email" /><i id="resulte_email"></i>
<br>
<input type="submit" name="create_account" /> <br />
<div id="resulte"></div>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment