forked from hussien89aa/swa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addUserSession.php
96 lines (80 loc) · 2.53 KB
/
addUserSession.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
<?php require 'headerTab.php';
if(isset($_SESSION["userName"])){
echo "User login is :". $_SESSION["userName"];
}else{
die("Cannot load page no permission");
return;
}
?>
<body>
<div class="container">
</br>
</br>
</br>
<form id='login' action="addUserSession.php" method='post' accept-charset='UTF-8'>
<div class="panel panel-primary">
<div class="panel-heading">Add User</div>
<div class="panel-body">
<div class="form-group">
<label for='username' >UserName*:</label>
<input type='text' name='userName' id='username' maxlength="50" required />
</div>
<div class="form-group">
<label for='password' >Password*:</label>
<input type='password' name='password' id='password' maxlength="50" required />
</div>
<input type='submit' class="btn btn-default" name='Submit' id='submit' value='Add' />
</div>
</div>
<a href="listUsers.php"> List all users</a>
</form>
</div>
<?php
//Database Authentication
require("DBInfo.inc");
// Server side code
//Read form submit info post request
$userName = $_POST['userName'];
$password = $_POST['password'];
//Fix problem of bayPass the restriction
if(!empty($userName) and !empty($password)) {
//Fix problem of BayPass the validation
$hasCharater=false;
if(preg_match('/[A-Za-z]/',$password)){
$hasCharater=true;
}
if($hasCharater==true){
//connect to database
$connect = mysqli_connect($hostDB, $userDB,$passwordDB,$databaseDB);
if(mysqli_connect_errno()){
die(" cannot connect to database ". mysqli_connect_error());
}
$query ="Insert into login(userName,password) VALUES ('" .
$userName ."','" . $password ."')" ;
$result= mysqli_query($connect,$query);
if (!$result){
die(' Error cannot run query');
}
mysqli_close($connect);
}
}
?>
<script>
var myInput = document.getElementById("password");
var submitBtn=document.getElementById("submit");;
submitBtn.disabled = true;
// When the user starts to type something inside the password field
myInput.onkeyup = function() {
submitBtn.disabled = true;
// Validate lowercase letters
var lowerCaseLetters = /[a-z]/g;
if (!myInput.value.match(lowerCaseLetters)) {
return;
}
if(myInput.value.length >5){
submitBtn.disabled = false;
}
}
</script>
</body>
<?php require 'footerTab.php'?>