/
insert.php
206 lines (160 loc) · 5.79 KB
/
insert.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
error_reporting(E_ALL);
function hashSSHA($password)
{
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}
function isUserExisted($email)
{
$db = new PDO('mysql:host=localhost:3308;dbname=fss-db', 'root', 'nabounanc1');
$query=$db->prepare("SELECT * FROM fss_users WHERE email = ':email' ");
$query->bindValue(':email', $email, PDO::PARAM_INT);
$query->execute();
// check for result
$no_of_rows = $query->rowCount();
if ($no_of_rows > 0)
{
// user existed
return true;
} else {
// user not existed
return false;
}
}
function getUserByEmailAndPassword($email, $password)
{
$db = new PDO('mysql:host=localhost:3308;dbname=fss-db', 'root', 'nabounanc1');
$query=$db->prepare("SELECT * FROM fss_users WHERE email = ':email' ");
$query->bindValue(':email', $email, PDO::PARAM_INT);
$query->execute();
// check for result
$no_of_rows = $query->rowCount();
if ($no_of_rows > 0)
{
$result = $query->fetchAll();
if (password_verify($password,$result['password'])) {
/* Valid */
// user authentication details are corre
return $result;
}
else
{
/* Invalid */
// user not found
return false;
}
}
}
function storeUser($name, $email, $password)
{
$uuid = uniqid('fss_u', true);
$hash = hashSSHA($password);
$encrypted_password = password_hash($password, PASSWORD_DEFAULT); // $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$regday = date("Y-m-j");
$type_user= 'admin';
$db = new PDO('mysql:host=localhost:3308;dbname=fss-db', 'root', 'nabounanc1');
echo $encrypted_password ;
echo '<br>';
$query=$db->prepare('INSERT INTO fss_users (unique_id,username,email,password,create_time,type_user) VALUES (:uuid, :name, :email, :encrypted_password, :regday, :type_user) ');
$query->bindValue(':uuid', $uuid, PDO::PARAM_STR);
$query->bindValue(':name', $name, PDO::PARAM_STR);
$query->bindValue(':email', $email, PDO::PARAM_STR);
$query->bindValue(':encrypted_password', $encrypted_password, PDO::PARAM_STR);
// $query->bindValue(':salt', $salt, PDO::PARAM_STR);
$query->bindValue(':regday', $regday, PDO::PARAM_STR);
$query->bindValue(':type_user', $type_user, PDO::PARAM_STR);
$query->execute();
// check for successful store
if ($query->execute())
{
echo $query->rowCount();
echo '<br>';
$result = $query->fetchAll();
print_r($result);
// get user details
$uid = $db->lastInsertId(); // last inserted id
$query=$db->prepare("SELECT * FROM fss_users WHERE unique_id = :uid");
$query->bindValue(':uid', $uid, PDO::PARAM_STR);
$query->execute();
//Message
$message = "Bienvenue sur FSS Votre inscription a ete accepte pseudo = $email mot de passe = $password !";
//Titre
$titre = "Bienvenue sur FSS !";
mail($email, $titre, $message); // Mail to the new user
// return user details
//return $query->fetchAll();
echo 'it\'s good';
echo '<br>';
}
else
{
echo 'error';
echo '<br>';
//return $false;
}
}
$name = "bachirdiop";
$email = "testing@hotmail.com";
$password = "bachirdiop3";
$email2 = 'diopisemou@gmail';
echo storeUser($name, $email, $password);
echo getUserByEmailAndPassword('diopisemou@gmail.com','bachirdiop3') ;
if(isUserExisted($email2))
echo 'il existe';
else
echo 'il existe pas ';
/*
$uuid = uniqid('fss_u', true);
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$regday = date("Y-m-j");
echo $hash["salt"] ;
echo '<br>';
echo $hash["encrypted"] ;
echo '<br>';
echo "INSERT INTO fss_users (unique_id,username,email,password,salt,create_time,type_user) VALUES('$uuid', '$name', '$email', '$encrypted_password', '$salt', '$regday','admin'); ";
echo '<br>';
$db = new PDO('mysql:host=localhost:3308;dbname=fss-db','diopbach','nabounanc1');
$query=$db->prepare('INSERT INTO fss_users (unique_id,username,email,password,salt,create_time,type_user) VALUES (:uuid, :name, :email, :encrypted_password, :salt, :regday, :type_user) ');
$query->bindValue(':uuid', $uuid, PDO::PARAM_STR);
$query->bindValue(':name', $name, PDO::PARAM_INT);
$query->bindValue(':email', $email, PDO::PARAM_STR);
$query->bindValue(':encrypted_password', $encrypted_password, PDO::PARAM_STR);
$query->bindValue(':salt', $salt, PDO::PARAM_STR);
$query->bindValue(':regday', $regday, PDO::PARAM_STR);
$query->bindValue(':type_user', $type_user, PDO::PARAM_STR);
$result = $query->execute();
$result = $query->fetch();
if ($result)
{
echo 'im here';
// get user details
$uid = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM fss_users WHERE email = $email");
// return user details
echo mysql_fetch_row($result);
} else
{
echo 'im not here';
require_once 'includes/script/files/DB_Functions.php';
$db = new DB_Functions();
echo $db->storeUser($name,$email, $password);
echo '<br>';
echo '<br>';
echo '<br>';
echo '<br>';
echo $db->getUserByEmailAndPassword($email, $password);
return $false;
}
echo mysql_fetch_array($result);
*/
?>