static function update_password($username, $password, $userID, $db) { if ($userID == '' or $password == '') { return false; } $salt = UserUtils::get_salt(); $encrypt_password = encpw($salt, $username, $password); $stmt = $db->prepare("UPDATE users SET password = ?, password_expire = NULL WHERE id = ?"); $stmt->bind_param('si', $encrypt_password, $userID); if (!$stmt->execute()) { $success = false; } else { $success = true; } $stmt->close(); return $success; }
function update_password($postauthsuccessobj = '') { $configObj = Config::get_instance(); $this->savetodebug('Called update_password'); if ($this->updatable === true and (!isset($this->settings['donotupdatepassword']) or isset($this->settings['donotupdatepassword']) and $this->settings['donotupdatepassword'] !== true)) { if ($configObj->get('cfg_password_expire') == null) { $days = 30; // If there is no setting in the config file, default to 30 days. } else { $days = $configObj->get('cfg_password_expire'); } $expire = time() + $days * 24 * 60 * 60; $this->savetodebug('Updating Password'); extract($this->settings); $encpw_details = encpw($this->settings['encrypt_salt'], $this->form['std']->username, $this->form['std']->password); $stmt = $this->db->prepare("UPDATE {$table} SET {$passwd_col} = ?, password_expire = ? WHERE {$username_col} = ?"); $stmt->bind_param('sis', $encpw_details, $expire, $this->form['std']->username); $stmt->execute(); $stmt->close(); } elseif (isset($this->settings['donotupdatepassword']) and $this->settings['donotupdatepassword'] === true) { $this->savetodebug('Not updating password due to settings flag'); } return $postauthsuccessobj; }
<?php $username = '******'; $password = gen_password(16); $role = 'Staff,SysCron'; // Add cron user to config file. $new_lines = array("// cron user login credentials\n", "\$cfg_cron_user = '******';\n", "\$cfg_cron_passwd = '{$password}';\n"); $target_line = '$percent_decimals'; $updater_utils->add_line($string, '$cfg_cron_user', $new_lines, 28, $cfg_web_root, $target_line, -2); // Add cron user to database. $usercheck = $updater_utils->count_rows("SELECT id FROM users WHERE username = '******'"); if (!$usercheck) { $salt = UserUtils::get_salt(); $encrypt_password = encpw($salt, $username, $password); $updater_utils->execute_query("INSERT INTO users (username, password, surname, roles) VALUES ('{$username}', '{$encrypt_password}', '{$username}', '{$role}')", true); } /* ***** NOW UPDATE THE INSTALLER SCRIPT ***** */