-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
94 lines (78 loc) · 3.44 KB
/
signup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
include('connecttodb.php');
$name=$password=$email='';
$ermsg = array('name'=>'','mail'=>'','pass'=>''); #error messages list
if (isset($_POST['submit'])) {
$name = htmlspecialchars($_POST['user_name']);
if (filter_var(htmlspecialchars($_POST['user_email']),FILTER_VALIDATE_EMAIL)){ #checking validity of email
$email = htmlspecialchars($_POST['user_email']);
}
else{
$ermsg['mail'] = 'Enter valid email';
}
$password = htmlspecialchars($_POST['user_password1']);
if (!array_filter($ermsg)) {
$name = mysqli_real_escape_string($conn,$_POST['user_name']);
$email = mysqli_real_escape_string($conn,$_POST['user_email']);
$password = mysqli_real_escape_string($conn,$_POST['user_password1']);
$sql= "INSERT INTO users(name,email,password) VALUES('$name','$email','$password') " ;
if(mysqli_query($conn,$sql)){
header("Location: home.php?user=".$name);
}
else{
echo "saving values to db failed";
}
}
}
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up Form</title>
<link rel="stylesheet" href="signup.css">
<link href='https://fonts.googleapis.com/css?family=Nunito:400,300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="signup.css">
</head>
<body>
<form action="signup.php" method="post" name="sform" id="sform" onSubmit="return validate()" >
<h1>Sign Up</h1>
<fieldset>
<label for="name">Name:</label>
<input type="text" id="name" name="user_name" value="<?php echo $name;?>" required>
<label for="mail">Email:</label>
<input type="email" id="mail" name="user_email" value="<?php echo $email;?>" required>
<div class="red"><?php echo $ermsg['mail'];?></div>
<label for="password">Password:</label>
<input type="password" id="password1" name="user_password1" value="<?php echo $password;?>" required>
<div id="error" class="red"></div>
<label for="password">Enter password again:</label>
<input type="password" id="password2" name="user_password2" value="<?php echo $password;?>" required>
</fieldset>
<button type="submit" name="submit">Sign Up</button>
</form>
<!-- client side scripting for validating password and checking the format of apssword -->
<script>
function validate() { //validating password
var pass1 = document.getElementById('password1').value;
var pass2 = document.getElementById('password2').value;
if (pass1 == pass2) {
min = 6;
regex = /^(?=.*[0-9])(?=.*[!@#$%^&*])(?=.*[A-Z])[a-zA-Z0-9!@#$%^&*]{6,}$/; //regular expression for password
//regular expression defines how the password should be
if (!regex.test(pass1)) { //checking password with regular expression
document.getElementById("error").innerHTML = "Password must contain atleast one specail character,number and uppercase letter(mininum length must be 6)";
return false;
}
else{
return true;
}
}
else{
alert("Passwords doesn't match");
return false;
}
}
</script>
</body>
</html>