Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by JetBrains PhpStorm.
- * User: Serenity
- * Date: 20-6-11
- * Time: 10:59
- * To change this template use File | Settings | File Templates.
- */
- define('SALT', 'pxNg5ODJha5PF6JoqUeYxDA');
- define('KEY', '558F9228641C37A9694BAB7C31397');
- require_once(Config::acquire('Item', null, 'item'));
- class Account extends Item
- {
- private $id;
- private $username;
- private $password;
- private $clearence =-1;
- /**
- * construction Account Item
- *
- * @param $username the username of the account
- * @param $password the password of the account
- * @param $clearence the level clearence the account has.
- */
- public function __construct($username='', $password ='', $clearence='')
- {
- $this->username = $username;
- $this->password = $password;
- $this->clearence = $clearence;
- }
- /**
- * retrieve an account from the database
- * @static
- * @param $id the id from wich to get the account details from.
- * @return Account|null
- */
- public static function read($username)
- {
- $account = SQL::query("SELECT * FROM `account` where `Account_Gebruikersnaam` = '$username'");
- if ($account->isValid()) {
- return new Account($account->fetchField('Account_Gebruikersnaam'), $account->fetchField('Account_Password'), $account->fetchField('Account_Level'));
- } else {
- return null;
- }
- }
- /**
- * encrypt a string or password
- *
- * @param null $text default encrypts the password otherwise decrypts the string
- * @return string returns the encrypted string/password.
- */
- public function encrypt($text = null)
- {
- if (is_null($text)) {
- return md5(sha1(crc32(md5(base64_decode($this->password . SALT)) . SALT)));
- } else {
- return md5(sha1(crc32(md5(base64_decode($text . SALT)) . SALT)));
- }
- }
- /**
- * log the account and validate it.
- *
- * @static
- * @param null $username the username to log in with.
- * @param null $password the password to log in with
- * @return bool true if its a valid login.
- */
- public static function validate($username = null, $password = null)
- {
- if (!is_null($username) && !is_null($password)) {
- $account = self::read($username);
- if (!is_null($account)) {
- if (strcmp($account->encrypt(), $account->encrypt($password)) == 0) {
- Register::set('account', $account, true);
- Register::set('public key', KEY, true);
- return true;
- }
- return false;
- }
- } else {
- if (is_null(Register::get('public key', true))) {
- return false;
- } else {
- if (strcmp(Register::get('public key', true), KEY) == 0)
- return true;
- return false;
- }
- }
- }
- public function getClearence()
- {
- return $this->clearence;
- }
- public function getPassword()
- {
- return $this->password;
- }
- public function getUsername()
- {
- return $this->username;
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement