<?php
session_start();include 'common.php';if(!isset($_SESSION['user'])){header("Location:login.php");exit;}$u=$_SESSION['user'];$m='';if($_SERVER['REQUEST_METHOD']==='POST'){$o=$_POST['oldpwd']??'';$n=$_POST['newpwd']??'';$n2=$_POST['newpwd2']??'';$f='user/'.APPID1.suffix;$us=[];if(file_exists($f)){$j=file_get_contents($f);$us=json_decode($j,true);if(!is_array($us))$us=[];}if(!isset($us[$u])||!password_verify($o,$us[$u])){$m='原密码错误';}elseif(!$n||strlen($n)<4){$m='新密码不能少于4位';}elseif($n!==$n2){$m='两次输入的新密码不一致';}else{$us[$u]=password_hash($n,PASSWORD_DEFAULT);file_put_contents($f,json_encode($us,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT));$m='密码修改成功';session_destroy();header("refresh:2;url=login.php");exit;}}?>
<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><title>修改密码</title><meta name="viewport" content="width=device-width,initial-scale=1"><style>body{font-family:Arial,"微软雅黑",sans-serif;margin:0;padding:0}.form-box{width:100%;max-width:520px;margin:70px auto 0;box-sizing:border-box}.form-box form{display:flex;flex-direction:column;gap:20px}.form-box input[type="password"]{font-size:20px;padding:16px 12px;border-radius:6px;border:1px solid #e4e7ed;background:#f7f9fa;outline:none;transition:border-color .2s;box-sizing:border-box}.form-box input[type="password"]:focus{border-color:#a0a0a0}.form-box input[type="submit"]{font-size:24px;padding:14px 0;background:#393f44;color:#fff;border:none;border-radius:6px;cursor:pointer;letter-spacing:6px;margin:8px 0;transition:background .2s}.form-box input[type="submit"]:hover{background:#23272b}.msg{color:#d8000c;text-align:center;margin-bottom:14px;font-size:16px;font-weight:700}.link-row{text-align:center;margin-top:24px;font-size:16px}.link-row a{color:#393f44;text-decoration:underline;margin-left:8px}@media (max-width:600px){.form-box{margin-top:28px;padding:0 2vw}.form-box input[type="password"]{font-size:16px;padding:12px 8px}.form-box input[type="submit"]{font-size:18px;padding:10px 0}.link-row{font-size:14px}}</style></head><body><div class="form-box"><?php if($m)echo"<div class='msg'>$m</div>";?><form method="post" autocomplete="off"><input type="password" name="oldpwd" placeholder="原密码" required><input type="password" name="newpwd" placeholder="新密码" required><input type="password" name="newpwd2" placeholder="再次输入新密码" required><input type="submit" value="修改密码"></form><div class="link-row"></div></div><?php include'footer.php';?></body></html>