NewHome/admin/force_password.php

73 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* admin/force_password.php —— 初始 / 重置密码未修改前的强制改密页
* 说明:默认管理员(或标记了 must_change_pwd 的账号)登录后,未改密前不得进入其它后台页面。
*/
$P = '../';
require_once dirname(__DIR__) . '/includes/auth.php';
require_once dirname(__DIR__) . '/includes/layout.php';
if (!is_logged_in()) {
header('Location: login.php');
exit;
}
// 已完成改密的账号无需停留在本页
if (!hp_password_needs_change()) {
header('Location: nav.php');
exit;
}
$err = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!csrf_verify()) {
$err = '安全校验失败,请刷新页面重试。';
} else {
$np = (string) ($_POST['new_pwd'] ?? '');
$np2 = (string) ($_POST['new_pwd2'] ?? '');
if ($np !== $np2) {
$err = '两次输入的新密码不一致。';
} else {
[$ok, $text] = hp_change_password((string) ($_POST['old_pwd'] ?? ''), $np);
if ($ok) {
header('Location: nav.php');
exit;
}
$err = $text;
}
}
}
$site = setting_get('site_name', 'SecHome');
layout_head('首次登录修改密码');
?>
<main class="page-main">
<div class="wrap page-body" style="max-width:520px;margin:40px auto">
<div class="fieldset-card">
<div class="fs-title">安全提醒:请先修改初始密码</div>
<p class="tip" style="margin:6px 0 14px">
检测到当前账号仍在使用初始密码。为防止后台被未授权访问,必须修改密码后方可进入其它管理页面。
</p>
<?php if ($err !== ''): ?>
<div class="err-msg"><?= he($err) ?></div>
<?php endif; ?>
<form method="post" autocomplete="off">
<?= csrf_field() ?>
<label class="fl">当前密码(初始为 admin123</label>
<input type="password" name="old_pwd" required autocomplete="off" autofocus>
<label class="fl">新密码(至少 6 位)</label>
<input type="password" name="new_pwd" required minlength="6" autocomplete="off">
<label class="fl">确认新密码</label>
<input type="password" name="new_pwd2" required minlength="6" autocomplete="off">
<div class="field-row" style="margin-top:14px">
<button type="submit" class="btn btn-primary">修改并继续</button>
<a class="btn" href="logout.php">退出登录</a>
</div>
</form>
</div>
</div>
</main>
<?php layout_theme_fab(); ?>
<script src="../assets/js/common.js"></script>
</body>
</html>