-
Notifications
You must be signed in to change notification settings - Fork 0
/
signUp.php
107 lines (85 loc) · 3.27 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
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
require("./Database/config.php");
$connectionString = Config::getConnectionString();
$connection = pg_connect($connectionString);
$USEREXISTS = 0;
function runQuery($query)
{
GLOBAL $connection;
$res = pg_query($connection, $query);
return $res;
}
function userExists($userName)
{
$query = "SELECT * from users where username='{$userName}'";
$res = runQuery($query);
$noOfRows = pg_num_rows($res);
if($noOfRows == 0)
return false;
return true;
}
if(isset($_POST["signup"]))
{
$username = htmlentities($_POST['username']);
$password = $_POST['password'];
$forgotQNo = $_POST['forgotPassQuestion'];
$answer = strtolower(htmlentities($_POST['answer']));
if(userExists($username))
{
$USEREXISTS=1;
}
else
{
$query="INSERT INTO users VALUES('{$username}','{$password}',$forgotQNo,'$answer')";
$res=runQuery($query);
if(!$res)
$USEREXISTS=3;
else
$USEREXISTS=2;
setcookie("username",$userName,time()+3600*24,'/');
header("Location:./frontPage.php");
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./Styles/login.css">
<link rel="icon" href="Images/icon.png" type="image/gif" sizes="16x16">
<title>Sign Up</title>
</head>
<body>
<div class="login_container">
<div class="login_greeting">
<div class="welcome_title">Welcome To Typing Wizards</div>
<div class="welcome_message">Sign Up to start using</div>
</div>
<div class="login_form">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" class="form">
<span class="sign_title">Sign Up</span>
<span class="label">Username</span>
<input type="text" name="username" class="input username">
<?php if($USEREXISTS==1): ?>
<span class="wrong">User already exists !</span>
<?php else : ?>
<span class="wrong">Invalid Username!</span>
<?php endif ?>
<span class="label">Password</span>
<input type="password" name="password" class="input password">
<span class="wrong">Invalid Password!</span>
<span class="label">Security Question</span>
<select name="forgotPassQuestion" class="select_menu">
<option value="1">What was your childhood nickname?</option>
<option value="2">What is your favorite game?</option>
<option value="3">Who is your childhood sports hero?</option>
</select>
<input type="text" name="answer" class="input forgotPassAnswer">
<input type="submit" value="Sign Up" name="signup" class="signup_button">
</form>
</div>
</div>
</body>
<script src="./Js/signup.js"></script>
</html>