Skip to content

Commit f8d1c71

Browse files
committed
update
1 parent 71d93b3 commit f8d1c71

File tree

4 files changed

+57
-72
lines changed

4 files changed

+57
-72
lines changed

header.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<?php
2-
session_start();
3-
?>
41

52
<!DOCTYPE html>
63
<html lang="en" dir="ltr">

index.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
include_once('footer.php');
44
include_once('db.php');
55

6-
/*$strSQL = "SELECT * FROM users WHERE username = '".$_SESSION['username']."'";*/
76
?>
87
<!DOCTYPE html>
98
<html lang="en" dir="ltr">
@@ -15,9 +14,6 @@
1514
</head>
1615
<body>
1716
<p>Welcome
18-
<!-- <strong>
19-
<?php echo $_SESSION [username]; ?>
20-
</strong> -->
2117
</p>
2218
</body>
2319
</html>

login.php

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,44 @@
11
<?php
2-
if ( isset($_POST['login']) ) {
3-
//un champ obligatoire
4-
if ( !empty($_POST['username']) )
5-
{
6-
$username = trim($_POST['username']) ;
7-
}
8-
else
9-
{
10-
$mistakes['username'] = true;
11-
}
12-
13-
if ( !empty($_POST['password']) )
14-
{
15-
$password = trim($_POST['password']) ;
16-
$passhash = password_hash($password,PASSWORD_DEFAULT);
17-
}
18-
else
19-
{
20-
$mistakes['password'] = true;
21-
}
22-
print_r($mistakes);
23-
//s'il n'y a pas d'erreur...
24-
if (empty($mistakes))
25-
{
26-
include("db.php");
27-
28-
$req=$bd->prepare('SELECT * FROM users WHERE username = :username');
29-
$req->bindValue(':username', $username, PDO::PARAM_STR);
30-
$req->execute();
31-
$data=$req->fetch();
32-
if (password_verify($password, $data['password']))
33-
{
34-
$_SESSION['username']=$data['username'];
35-
$_SESSION['rights']=$data['rights'];
2+
session_start();
3+
include("db.php");
4+
?>
5+
<?php
6+
$msg = "";
7+
if(isset($_POST['login'])) {
8+
$email = trim($_POST['email']);
9+
$password = trim($_POST['password']);
10+
$passhash = sha1($password);
11+
if($email != "" && $password != "") {
12+
try {
13+
$query = "select * from `users` where `email`=:email and `passhash`=:password";
14+
$stmt = $bd->prepare($query);
15+
$stmt->bindParam('email', $email, PDO::PARAM_STR);
16+
$hashed = sha1($password);
17+
$stmt->bindParam('password',$hashed, PDO::PARAM_STR);
18+
$stmt->execute();
19+
$count = $stmt->rowCount();
20+
$row = $stmt->fetch(PDO::FETCH_ASSOC);
21+
echo "test";
22+
if($count == 1 && !empty($row)) {
23+
/******************** Your code ***********************/
24+
$_SESSION['sess_id'] = $row['id'];
25+
$_SESSION['sess_username'] = $row['username'];
26+
$_SESSION['sess_email'] = $row['email'];
27+
$_SESSION['sess_firstName'] = $row['firstName'];
28+
$_SESSION['sess_lastName'] = $row['lastName'];
29+
$_SESSION['sess_rights'] = $row['rights'];
30+
$_SESSION['sess_active'] = $row['active'];
31+
echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
32+
echo "teub";
33+
} else {
34+
$msg = "Invalid username and password!";
35+
}
36+
} catch (PDOException $e) {
37+
echo "Error : ".$e->getMessage();
3638
}
37-
38-
39-
$req->closeCursor();
40-
header("Location:index.php");
41-
42-
exit();
43-
44-
45-
46-
}
47-
else{
48-
49-
}
39+
} else {
40+
$msg = "Both fields are required!";
41+
}
5042
}
5143
?>
5244
<!DOCTYPE html>
@@ -61,16 +53,18 @@
6153
<link rel="stylesheet" href="Custom/css/login.css">
6254
</head>
6355
<body>
64-
<form class='login-form' method="POST">
56+
<h1>Log in</h1>
57+
58+
<form class='login-form' method="POST" action="login.php">
6559
<div class="flex-row">
66-
<label class="lf--label" for="username">
60+
<label class="lf--label" for="email">
6761
<svg x="0px" y="0px" width="12px" height="13px">
6862
<path fill="#B1B7C4" d="M8.9,7.2C9,6.9,9,6.7,9,6.5v-4C9,1.1,7.9,0,6.5,0h-1C4.1,0,3,1.1,3,2.5v4c0,0.2,0,0.4,0.1,0.7 C1.3,7.8,0,9.5,0,11.5V13h12v-1.5C12,9.5,10.7,7.8,8.9,7.2z M4,2.5C4,1.7,4.7,1,5.5,1h1C7.3,1,8,1.7,8,2.5v4c0,0.2,0,0.4-0.1,0.6 l0.1,0L7.9,7.3C7.6,7.8,7.1,8.2,6.5,8.2h-1c-0.6,0-1.1-0.4-1.4-0.9L4.1,7.1l0.1,0C4,6.9,4,6.7,4,6.5V2.5z M11,12H1v-0.5 c0-1.6,1-2.9,2.4-3.4c0.5,0.7,1.2,1.1,2.1,1.1h1c0.8,0,1.6-0.4,2.1-1.1C10,8.5,11,9.9,11,11.5V12z"/>
6963
</svg>
7064
</label>
71-
<input id="username" name="username" class='lf--input' placeholder='Username' type='text'
72-
<?php if(isset($username)) echo 'value="', $username; ?>>
65+
<input type="email" name="email" class="lf--input" id="email" required="" placeholder="Email">
7366
</div>
67+
7468
<div class="flex-row">
7569
<label class="lf--label" for="password">
7670
<svg x="0px" y="0px" width="15px" height="5px">
@@ -79,7 +73,7 @@
7973
</g>
8074
</svg>
8175
</label>
82-
<input id="password" name="password" class='lf--input' placeholder='Password' type='password'>
76+
<input type="password" name="password" class="lf--input" id="password" required="" placeholder="Password">
8377
</div>
8478
<input class='lf--submit' type='submit' name='login' value='LOGIN'>
8579
</form>

signin.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
2+
include"db.php";
23

4+
$username = $password = $confirmPassword = "";
5+
$username_err = $password_err = $confirmPassword_err = "";
36
if ( isset($_POST['completed']) ) {
47
//un champ obligatoire
58
if ( !empty($_POST['username']) )
@@ -12,18 +15,16 @@
1215
}
1316

1417
if ( !empty($_POST['email'])){
15-
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
1618
$email = trim($_POST['email']) ;
17-
}
1819
}
1920
else
2021
{
2122
$mistakes['email'] = true;
2223
}
2324

2425

25-
if ( !empty($_POST['password']) AND isset($_POST['confirmPassword'])){
26-
if ($_POST["password"]== $_POST["confirmPassword"]) {
26+
if ( !empty($_POST['password']) AND isset($_POST['cpassword'])){
27+
if ($_POST["password"]== $_POST["cpassword"]) {
2728
$password = trim($_POST['password']);
2829
$passhash = sha1($password);
2930
}
@@ -76,17 +77,17 @@
7677
<link rel="stylesheet" href="Custom/css/login.css">
7778
</head>
7879
<body>
80+
<h1>Registration</h1>
7981

80-
<form method="POST" class='login-form' action="signin.php">
82+
<form method="post" class='login-form' action="signin.php">
8183

8284
<div class="flex-row">
8385
<label class="lf--label" for="username">
8486
<svg x="0px" y="0px" width="12px" height="13px">
8587
<path fill="#B1B7C4" d="M8.9,7.2C9,6.9,9,6.7,9,6.5v-4C9,1.1,7.9,0,6.5,0h-1C4.1,0,3,1.1,3,2.5v4c0,0.2,0,0.4,0.1,0.7 C1.3,7.8,0,9.5,0,11.5V13h12v-1.5C12,9.5,10.7,7.8,8.9,7.2z M4,2.5C4,1.7,4.7,1,5.5,1h1C7.3,1,8,1.7,8,2.5v4c0,0.2,0,0.4-0.1,0.6 l0.1,0L7.9,7.3C7.6,7.8,7.1,8.2,6.5,8.2h-1c-0.6,0-1.1-0.4-1.4-0.9L4.1,7.1l0.1,0C4,6.9,4,6.7,4,6.5V2.5z M11,12H1v-0.5 c0-1.6,1-2.9,2.4-3.4c0.5,0.7,1.2,1.1,2.1,1.1h1c0.8,0,1.6-0.4,2.1-1.1C10,8.5,11,9.9,11,11.5V12z"/>
8688
</svg>
8789
</label>
88-
<input id="username" name="username" class='lf--input' placeholder='Username' type='text'
89-
<?php if(isset($username)) echo 'value="',$username,'"';?>>
90+
<input type="text" name="username" class="lf--input" id="username" required="" placeholder="Username">
9091
</div>
9192

9293
<div class="flex-row">
@@ -95,8 +96,7 @@
9596
<path fill="#B1B7C4" d="M8.9,7.2C9,6.9,9,6.7,9,6.5v-4C9,1.1,7.9,0,6.5,0h-1C4.1,0,3,1.1,3,2.5v4c0,0.2,0,0.4,0.1,0.7 C1.3,7.8,0,9.5,0,11.5V13h12v-1.5C12,9.5,10.7,7.8,8.9,7.2z M4,2.5C4,1.7,4.7,1,5.5,1h1C7.3,1,8,1.7,8,2.5v4c0,0.2,0,0.4-0.1,0.6 l0.1,0L7.9,7.3C7.6,7.8,7.1,8.2,6.5,8.2h-1c-0.6,0-1.1-0.4-1.4-0.9L4.1,7.1l0.1,0C4,6.9,4,6.7,4,6.5V2.5z M11,12H1v-0.5 c0-1.6,1-2.9,2.4-3.4c0.5,0.7,1.2,1.1,2.1,1.1h1c0.8,0,1.6-0.4,2.1-1.1C10,8.5,11,9.9,11,11.5V12z"/>
9697
</svg>
9798
</label>
98-
<input id="email" name="email" class='lf--input' placeholder='Email' type='text'
99-
<?php if(isset($email)) echo 'value="',$email,'"';?>>
99+
<input type="email" name="email" class="lf--input" id="email" required="" placeholder="Email">
100100
</div>
101101

102102
<div class="flex-row">
@@ -107,8 +107,7 @@
107107
</g>
108108
</svg>
109109
</label>
110-
<input id="password" name="password" class='lf--input' placeholder='Password' type='password'
111-
<?php if(isset($password)) echo 'value="',$password,'"';?>>
110+
<input type="password" name="password" class="lf--input" id="password" required="" placeholder="Password">
112111
</div>
113112

114113
<div class="flex-row">
@@ -119,8 +118,7 @@
119118
</g>
120119
</svg>
121120
</label>
122-
<input id="confirmPassword" name="confirmPassword" class='lf--input' placeholder='Confirm the password' type='password'
123-
<?php if(isset($confirmPassword)) echo 'value="',$confirmPassword,'"';?>>
121+
<input type="password" name="cpassword" class="lf--input" id="cpassword" required="" placeholder="Password confirmation">
124122
</div>
125123

126124
<input class='lf--submit' type='submit' name="completed" value='SIGN IN'>

0 commit comments

Comments
 (0)