-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
119 lines (103 loc) · 2.77 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
108
109
110
111
112
113
114
115
116
117
118
119
<?php
require_once "pdo.php";
require_once "util.php";
session_start();
if(isset($_POST['cancel'])){
header("Location: index.php");
return;
}
if(isset($_POST['username'])&&isset($_POST['password'])&&isset($_POST['password2'])){
unset($_SESSION['account']);
if(strlen($_POST['username'])==0||strlen($_POST['password'])==0||strlen($_POST['password2'])==0){
$_SESSION['error']="Please enter User Name and Password";
header("Location: signup.php");
return;
}
if($_POST['password']!==$_POST['password2']){
$_SESSION['error']="Password and Confirm Password did not match";
header("Location: signup.php");
return;
}
$stmt=$pdo->prepare("SELECT * FROM user WHERE user_name=:us");
$stmt->execute(array(':us'=>$_POST['username']));
$row=$stmt->fetch(PDO::FETCH_ASSOC);
if($row!==false){
$_SESSION['error']="User Name already exist.";
header("Location: signup.php");
return;
}
$salt='XyZzy12*_';
$check=hash('md5',$salt.$_POST['password']);
$stmt=$pdo->prepare("INSERT INTO user(user_name,password) VALUES (:us,:pw)");
$stmt->execute(array(
':us'=>$_POST['username'],
':pw'=>$check));
$_SESSION['account']=$pdo->lastInsertId();
$_SESSION['success']="Account created successfully";
error_log("Signup success ".$_POST['username']." ".$_POST['password']);
header("Location: main.php");
return;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login here</title>
</head>
<body>
<style>
h1{
text-align:center;
font-family:serif;
color:black;
font-size:350%;
}
input[type=submit]{
background-color:transparent;
opacity:0.7;
font-size:15px;
padding:13px 30px;
color:black;
border-radius:8px;
box-shadow:0 6px 6px rgb(0,0,0,0.6);
cursor: pointer;
border: 1px solid #3498db;
font-family:serif;
}
input[type=text] {
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
font-family:serif;
}
input[type=password] {
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
font-family:serif;
}
body,html{
background-image:url("https://images7.alphacoders.com/996/thumb-1920-996873.jpg");
height:100%;
background-repeat:no-repeat;
background-attachment:fixed;
background-size:cover;
}
</style>
<h1>Signup</h1><br><br>
<?php
flash();
?>
<form autocomplete="on" method="post">
<center>
<label for="username">Username:</label><br>
<input type="text" id="username" name="username" placeholder="username" autofocus ><br><br>
<label for="password" style="text-align:right;">Password:</label><br>
<input type="password" id="password" name="password" placeholder="password" ><br><br>
<label for="password2" style="text-align:right;"></label><br>
<input type="password" id="password2" name="password2" placeholder="Confirm Password" ><br><br>
<input type="submit" name= "create" value="Create Account">
<input type="submit" name= "cancel" value="Cancel" id="cancel">
</form>
</body>
</html>