Skip to content

Commit bf1b5c7

Browse files
caseysoftwareclaude
andcommitted
Store changed passwords as typed and report the real save result
chpwd.php passed the old and new passwords through the database escape function before validating and hashing them. They never reach SQL as text, so a password containing ' or \ was stored with extra backslashes and could not be used to log in. It also trimmed them, unlike the login form. The passwords are now read the same way index.php reads the login password. The result branches were also inverted in effect: a failed save showed "Your password has been updated", and a successful one only closed the window (which does nothing when the page was not opened as a popup). A success now shows the message before closing; a failure shows the save errors. Refs #386 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CP89WVmGZ1VVCCZMS6ntN
1 parent b8fdfd0 commit bf1b5c7

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎modules/public/chpwd.php‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
// check for a non-zero user id
1212
if ($user_id) {
13-
$old_pwd = (new w2p_Database_Connection($GLOBALS['db']))->escape(trim(w2PgetParam($_POST, 'old_pwd', null)));
14-
$new_pwd1 = (new w2p_Database_Connection($GLOBALS['db']))->escape(trim(w2PgetParam($_POST, 'new_pwd1', null)));
15-
$new_pwd2 = (new w2p_Database_Connection($GLOBALS['db']))->escape(trim(w2PgetParam($_POST, 'new_pwd2', null)));
13+
// Read the passwords exactly as the login form does (index.php). They are
14+
// hashed, never put into SQL, so escaping them here would change the
15+
// password that gets stored.
16+
$old_pwd = (string) w2PgetParam($_POST, 'old_pwd', '');
17+
$new_pwd1 = (string) w2PgetParam($_POST, 'new_pwd1', '');
18+
$new_pwd2 = (string) w2PgetParam($_POST, 'new_pwd2', '');
1619

1720
$perms = &$AppUI->acl();
1821
$canAdminEdit = canEdit('system');
@@ -26,7 +29,10 @@
2629
$user->user_password = $new_pwd1;
2730
$result = $user->store();
2831

32+
echo '<h1>' . $AppUI->_('Change User Password') . '</h1>';
33+
echo $AppUI->getTheme()->styleRenderBoxTop();
2934
if ($result) {
35+
echo '<div class="std p-2">' . $AppUI->_('chgpwUpdated') . '</div>';
3036
?>
3137
<script language="javascript" type="text/javascript">
3238
window.onload = function() {
@@ -35,9 +41,7 @@
3541
</script>
3642
<?php
3743
} else {
38-
echo '<h1>' . $AppUI->_('Change User Password') . '</h1>';
39-
echo $AppUI->getTheme()->styleRenderBoxTop();
40-
echo '<div class="std p-2">' . $AppUI->_('chgpwUpdated') . '</div>';
44+
echo '<div class="std p-2 text-danger">' . w2PformSafe(implode(' ', (array) $user->getError())) . '</div>';
4145
}
4246
} else {
4347
echo '<h1>' . $AppUI->_('Change User Password') . '</h1>';

0 commit comments

Comments
 (0)