如何通过PHP脚本重置密码

wdzsjl 1个月前 (10-10) 阅读数 18 #PHP
<?php $servername = "localhost"; $username = "your_username"; $password = "your_password"; $dbname = "your_database";  // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname);  // 检测连接 if ($conn->connect_error) {     die("Connection failed: " . $conn->connect_error); }  // 新密码 $new_password = "your_new_password"; $hashed_password = password_hash($new_password, PASSWORD_DEFAULT);  // 更新密码 $sql = "UPDATE users SET password = ? WHERE username = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param("ss", $hashed_password, $username);  $username = "your_admin_username"; // 替换成你的管理员用户名 $stmt->execute();  echo "Password reset successfully."; $stmt->close(); $conn->close(); ?>

 

wx.jpg ywfw.jpg
热门