- 회원가입·비밀번호 변경·관리자 회원 등록/수정에 정책 적용 - 정규식 규칙을 배열 형식으로 적용(파이프 파싱 깨짐 → is_unique 등 검증 무력화 버그 수정) - 비밀번호 입력란에 형식 안내문구 추가 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
57 lines
2.1 KiB
PHP
57 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\Controllers\BaseController;
|
|
use App\Models\MemberModel;
|
|
|
|
class PasswordChange extends BaseController
|
|
{
|
|
public function index()
|
|
{
|
|
helper('admin');
|
|
|
|
return $this->renderWorkPage('비밀번호 변경', 'admin/password_change/index');
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
helper('admin');
|
|
$rules = [
|
|
'current_password' => 'required',
|
|
'new_password' => ['required', 'min_length[8]', 'max_length[255]', 'regex_match[/^(?=.*[A-Za-z])(?=.*\d)(?=.*[\W_]).+$/]'],
|
|
'new_password_confirm' => 'required|matches[new_password]',
|
|
];
|
|
$messages = [
|
|
'current_password' => ['required' => '현재 비밀번호를 입력해 주세요.'],
|
|
'new_password' => [
|
|
'required' => '새 비밀번호를 입력해 주세요.',
|
|
'min_length' => '비밀번호는 8자 이상이어야 합니다.',
|
|
'regex_match' => '비밀번호는 영문·숫자·특수문자를 모두 포함해야 합니다.',
|
|
],
|
|
'new_password_confirm' => [
|
|
'required' => '비밀번호 확인을 입력해 주세요.',
|
|
'matches' => '새 비밀번호가 일치하지 않습니다.',
|
|
],
|
|
];
|
|
|
|
if (! $this->validate($rules, $messages)) {
|
|
return redirect()->back()->with('errors', $this->validator->getErrors());
|
|
}
|
|
|
|
$mbIdx = session()->get('mb_idx');
|
|
$memberModel = model(MemberModel::class);
|
|
$member = $memberModel->find($mbIdx);
|
|
|
|
if (!$member || !password_verify($this->request->getPost('current_password'), $member->mb_passwd)) {
|
|
return redirect()->back()->with('error', '현재 비밀번호가 올바르지 않습니다.');
|
|
}
|
|
|
|
$memberModel->update($mbIdx, [
|
|
'mb_passwd' => password_hash($this->request->getPost('new_password'), PASSWORD_DEFAULT),
|
|
]);
|
|
|
|
return redirect()->to(mgmt_url('password-change'))->with('success', '비밀번호가 변경되었습니다.');
|
|
}
|
|
}
|