From d8055192991ac8504e48c137038879790c762d2d Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 26 Jul 2016 14:27:14 +0200 Subject: Adding and deleting users --- classes/user.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'classes') diff --git a/classes/user.php b/classes/user.php index e50f773..750e8bb 100644 --- a/classes/user.php +++ b/classes/user.php @@ -33,6 +33,16 @@ class user { */ protected $pdo, $id, $username, $password; + /** + * Generate a random password + * + * @return string The password + */ + public static function generateRandomPassword() { + return preg_replace('/[^\w]/', '', + base64_encode(bin2hex(openssl_random_pseudo_bytes(4)))); + } + /** * Hash a password * @@ -140,6 +150,15 @@ class user { // Other functions //------------------------------------------------------------------------------ + /** + * Check if a user has administrator rights + * + * @return bool True iff the user has administrator rights + */ + public function isAdmin() { + return $this->getId() == 1; + } + /** * Verify a password * -- cgit v1.2.3