Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require_once 'connection.php';
- $conn = new Database;
- if(isset($_POST['btn-newpass']))
- {
- $username = strip_tags($_POST['username']);
- $password = md5(strip_tags($_POST['password']));
- $password_new = md5(strip_tags($_POST['password_new']));
- $password_new_conf = md5(strip_tags($_POST['password_new_conf']));
- $password_in_db = get_db_password($conn, $username);
- if($password_in_db === 0)
- {echo "Username-ul introdus nu există.";}
- else if($password != $password_in_db)
- {echo "Parola actuala introdusă este greşită.";}
- if($password_new == $password_new_conf)
- {change_password($conn, $username, $password_new);} else {echo "Parolele nu se potrivesc.";}
- }
- function get_db_password($conn, $username) {
- $count_stmt = $conn->prepare("SELECT COUNT(*) FROM utilizatori WHERE username = :username");
- $count_stmt->execute([':username' => $username]);
- $count = $count_stmt->fetchColumns();
- if($count <= 0)
- {return 0;}
- $stmt = $conn->prepare("SELECT password FROM utilizatori WHERE username = :username");
- $stmt->execute([':username' => $username]);
- $result = $stmt->fetch(PDO::FETCH_ASSOC);
- return $result['password'];
- }
- function change_password($conn, $username, $password_new) {
- $stmt = $conn->prepare("UPDATE utilizatori SET password = :password_new WHERE username = :username");
- $stmt->execute([
- ':password_new' => $password_new,
- ':username' => $username
- ]);
- $count = $stmt->rowCount();
- echo "Aţi schimbat parola cu succes! (".$count." intrari modificate)";
- }
- Am rezolvat taote bugurile in afara de Fatal error: Call to undefined method Database::prepare() in A:\XAMPP\htdocs\ATLx V5\change_password.php on line 25
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement