diff options
| -rw-r--r-- | app/class/user.class.php | 25 | 
1 files changed, 25 insertions, 0 deletions
| diff --git a/app/class/user.class.php b/app/class/user.class.php index 7defa8f..b0b3435 100644 --- a/app/class/user.class.php +++ b/app/class/user.class.php @@ -174,6 +174,31 @@ class user extends agent      }      /* +     * Initialize a new user object with the given username and plain +     * text password.  This function returns NULL if $uname is already +     * being used. +     */ +    public static function initNew(string $uname, string $passwd) : ?user +    { +        if (self::getByUname($uname)) +            return NULL; + +        $user = new user(); + +        /* if there exist no users already, make this new one an admin */ +        if (count(self::getAll_ordByUname()) == 0) +            $user->admin = 1; + +        $user->name = $uname; +        $user->objtype = "user"; +        $user->setPasswd($passwd); +        $user->setEmail(""); +        $user->reg = 1; + +        return $user; +    } + +    /*       * Get the salted and hashed form of a password       */      private static function getAuth(string $passwd, string $salt) : string | 
