Commit 3eb610f3 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Added two methods:

  - check if a user is suspended, and if so return some information about
  - change a users password to the given password

Removed the implementation of get_user_info, which is no longer needed now
that by default information is sourced from the database by the
authentication stuff.
parent ae7f9609
......@@ -47,10 +47,11 @@ class AuthInternal extends Auth {
* Given a user that we know about, return an array of information about them
* NOTE: Does not need to be implemented for the internal authentication
* method, as by default information is sourced from the database.
public static function get_user_info($username) {
$user = get_record('usr', 'username', $username, null, null, null, null, '*, ' . db_format_tsfield('expiry'));
return $user;
......@@ -91,6 +92,16 @@ class AuthInternal extends Auth {
return preg_match('/^[a-zA-Z0-9\._@]{3,30}$/', $username);
* Returns information about whether the given user is suspended
* @param object $user The user to check
* @return object Information relating to whether the user is suspended
public static function is_user_suspended($user) {
return get_record('usr_suspension', 'usr', $user->id);
* For internal authentication, passwords can contain a range of letters,
* numbers and symbols. There is a minimum limit of six characters allowed
......@@ -115,6 +126,22 @@ class AuthInternal extends Auth {
return true;
* Changes the user's password.
* @return string The new password, or empty if the password could not be set
public static function change_password($user, $password) {
// Create a salted password and set it for the user
$updateuser = new StdClass;
$updateuser->salt = substr(md5(rand(1000000, 9999999)), 2, 8);
$updateuser->password = self::encrypt_password($password, $updateuser->salt);
$where = new StdClass;
$where->username = $user->username;
update_record('usr', $updateuser, $where);
return $updateuser->password;
The following two functions are inspired by Andrew McMillan's salted md5
functions in AWL, adapted with his kind permission. Changed to use sha1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment