Class for working with users and passwords in a PHP CMS I'm working on CMS in PHP just for fun. Right now I'm trying to implement class for working with users/passwords. I had been reading lot of articles about hashing and as far as I understood crypt() function are the best(most secure) for now.

class Users {
    private static $key, $table, $logtable;

    public static function init($key) {
        self::$key = $key;
        self::$table = DBPREFIX.$key.'s';
        self::$logtable = self::$table.'_access_log';
    }

    public static function isLogged() {
        if(isset($_SESSION[self::$key])) {
            if(isset($_SESSION[self::$key]['uid'])) {
                $uid = intval($_SESSION[self::$key]['uid']);
                $user = DB::select()-&gt;from(self::$table)-&gt;where('id', '=', $uid)-&gt;execute()-&gt;object();
                if(count($user) &gt; 0) {
                    return true;
                }
                else {
                    return false;
                }

            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    }

    public static function userExist($login) {
        $user = DB::select()-&gt;from(self::$table)-&gt;where('login', '=', $login)-&gt;execute()-&gt;object();
        if(count($user) &gt; 0) {
            return true;
        }
        else {
            return false;
        }
    }

    public static function getUser($login) {
        $user = DB::select()-&gt;from(self::$table)-&gt;where('login', '=', $login)-&gt;execute()-&gt;object();
        if(count($user) &gt; 0) {
            return $user[0];
        }
        else {
            return false;
        }
    }

    public static function generateHash($password) {
        $salt = self::generateSalt();
        $hashedPassword = crypt($password, $salt);
        return array('hashed_password' =&gt; $hashedPassword, 'salt' =&gt; $salt);
    }

    private static function generateSalt() {
        $blowfishPre = '$2y$10$';
        $blowfishEnd = '$';
        $allowedChars ='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
        $charsLength = strlen($allowedChars);
        $saltLength = 20;
        $salt = "";
        for($i=0; $i &lt; $saltLength; $i++)
        {
            $salt .= $allowedChars[mt_rand(0,$charsLength)];
        }
        $bcrypt_salt = $blowfishPre . $salt . $blowfishEnd;
        return $bcrypt_salt;
    }

    public static function comparePasswords($input, $uid) {
        $user = DB::select()-&gt;from(self::$table)-&gt;where('id', '=', $uid)-&gt;execute()-&gt;object();
        if(count($user) &gt; 0) {
            $user = $user[0];
            $password = $user-&gt;password;
            return crypt($input, $password) === $password;
        }
        else {
            return false;
        }
    }

    public static function userExit() {
        if(isset($_SESSION[self::$key])) {
            unset($_SESSION[self::$key]);
        }
    }

    public static function changePassword($password, $uid) {
        $newPassword = self::generateHash($password);
        if(isset($newPassword['hashed_password']) &amp;&amp; isset($newPassword['salt'])) {
            DB::update(self::$table)-&gt;set(array('password' =&gt; $newPassword['hashed_password'], 'salt' =&gt; $newPassword['salt']))-&gt;where('id', '=', $uid)-&gt;execute();
        }
    }

    public static function updateTime($uid) {
        DB::update(self::$table)-&gt;set(array('last_login' =&gt; time()))-&gt;where('id', '=', $uid)-&gt;execute();
    }

    public static function writeAccessLog($uid, $success) {
        if($success) {
            DB::insert(self::$logtable)-&gt;set(array('admin_id' =&gt; $uid, 'date' =&gt; time(), 'success' =&gt; '1'))-&gt;execute();
        }
        else if(!$success) {
            DB::insert(self::$logtable)-&gt;set(array('admin_id' =&gt; $uid, 'date' =&gt; time(), 'success' =&gt; '0'))-&gt;execute();
        }
    }
}


Please, take a look and let me know if I doing something wrong.
New code (optimizations/simplifications, see comments in code for explanations):

class Users {
    private static $key, $table, $logtable;

    public static function init($key) {
        self::$key = $key;
        self::$table = DBPREFIX.$key.'s';
        self::$logtable = self::$table.'_access_log';
    }

    public static function isLogged() {
        if(isset($_SESSION[self::$key]) and isset($_SESSION[self::$key]['uid'])) { # Combined ifs
            $uid = intval($_SESSION[self::$key]['uid']);
            $user = DB::select()-&gt;from(self::$table)-&gt;where('id', '=', $uid)-&gt;execute()-&gt;object();
            return count($user) &gt; 0; # Simplified
        }
        return false; # Removed unnecesary elses
    }

    public static function userExist($login) {
        $user = DB::select()-&gt;from(self::$table)-&gt;where('login', '=', $login)-&gt;execute()-&gt;object();
        return count($user) &gt; 0; # Simplified
    }

    public static function getUser($login) {
        $user = DB::select()-&gt;from(self::$table)-&gt;where('login', '=', $login)-&gt;execute()-&gt;object();
        if(count($user) &gt; 0) {
            return $user[0];
        }
        return false; # Removed unnecessary else
    }

    public static function generateHash($password) {
        $salt = self::generateSalt();
        $hashedPassword = crypt($password, $salt);
        return array('hashed_password' =&gt; $hashedPassword, 'salt' =&gt; $salt);
    }

    private static function generateSalt($blowfishPre = '$2y$10$', $blowfishEnd = '$', $allowedChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./', $saltLength = 20) { # Added arguments for future customization
        $charsLength = strlen($allowedChars);
        $salt = "";
        for($i=0; $i &lt; $saltLength; $i++)
        {
            $salt .= $allowedChars[mt_rand(0,$charsLength)];
        }
        return $blowfishPre . $salt . $blowfishEnd; # Removed unnecessary variable
    }

    public static function comparePasswords($input, $uid) {
        $user = DB::select()-&gt;from(self::$table)-&gt;where('id', '=', $uid)-&gt;execute()-&gt;object();
        if(count($user) &gt; 0) {
            $user = $user[0];
            $password = $user-&gt;password;
            return crypt($input, $password) === $password;
        }
        return false; # Removed unnecessary else
    }

    public static function userExit() {
        if(isset($_SESSION[self::$key])) {
            unset($_SESSION[self::$key]);
        }
    }

    public static function changePassword($password, $uid) {
        $newPassword = self::generateHash($password);
        if(isset($newPassword['hashed_password']) &amp;&amp; isset($newPassword['salt'])) {
            DB::update(self::$table)-&gt;set(array('password' =&gt; $newPassword['hashed_password'], 'salt' =&gt; $newPassword['salt']))-&gt;where('id', '=', $uid)-&gt;execute();
        }
    }

    public static function updateTime($uid) {
        DB::update(self::$table)-&gt;set(array('last_login' =&gt; time()))-&gt;where('id', '=', $uid)-&gt;execute();
    }

    public static function writeAccessLog($uid, $success) {
        DB::insert(self::$logtable)-&gt;set(array('admin_id' =&gt; $uid, 'date' =&gt; time(), 'success' =&gt; $success ? '1' : '0'))-&gt;execute(); # Inlined success var.
    }
}