forked from ericzile/GWproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewPassword.php
More file actions
40 lines (39 loc) · 1.44 KB
/
newPassword.php
File metadata and controls
40 lines (39 loc) · 1.44 KB
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
<?php
include("conn.php");
header('Content-type: application/json ');
ini_set('display_errors','On');
$number=$_POST['numero'];
$user=array();
$response = array("success" => 0, "error" => 0);
$sql="SELECT * FROM user WHERE numero='$number'";
$req = $pdo->prepare($sql);
$req->execute();
$user = $req->fetchALL();
//print_r($user);
$nb = count($user);
if ($nb==1) {
$id = $user[0]["id_user"];
$pin = mt_rand(100000,999999);
$sql = "UPDATE user SET pin = :pin
WHERE id_user = :id";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':pin', $pin, PDO::PARAM_INT);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$resultat = $stmt->execute();
print_r("Resultat : ".$resultat);
if ($resultat == 1) {
$response["success"] = 1;
$response["msg"] = "Vous allez recevoir un message";
$response["pin"] = $pin;
echo json_encode($response);
}else{
$response["success"] = 0;
$response["msg"] = "Erreur dans la génération du mot de passe";
echo json_encode($response);
}
} else {
$response["success"] = 0;
$response["msg"] = "Numéro invalide";
echo json_encode($response);
}
?>