Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by JetBrains PhpStorm.
  4. * User: Serenity
  5. * Date: 20-6-11
  6. * Time: 10:59
  7. * To change this template use File | Settings | File Templates.
  8. */
  9.  
  10. define('SALT', 'pxNg5ODJha5PF6JoqUeYxDA');
  11. define('KEY', '558F9228641C37A9694BAB7C31397');
  12.  
  13. require_once(Config::acquire('Item', null, 'item'));
  14.  
  15.  
  16. class Account extends Item
  17. {
  18.  
  19. private $id;
  20. private $username;
  21. private $password;
  22. private $clearence =-1;
  23.  
  24.  
  25.  
  26. /**
  27. * construction Account Item
  28. *
  29. * @param $username the username of the account
  30. * @param $password the password of the account
  31. * @param $clearence the level clearence the account has.
  32. */
  33. public function __construct($username='', $password ='', $clearence='')
  34. {
  35. $this->username = $username;
  36. $this->password = $password;
  37. $this->clearence = $clearence;
  38. }
  39.  
  40. /**
  41. * retrieve an account from the database
  42. * @static
  43. * @param $id the id from wich to get the account details from.
  44. * @return Account|null
  45. */
  46. public static function read($username)
  47. {
  48.  
  49.  
  50. $account = SQL::query("SELECT * FROM `account` where `Account_Gebruikersnaam` = '$username'");
  51. if ($account->isValid()) {
  52. return new Account($account->fetchField('Account_Gebruikersnaam'), $account->fetchField('Account_Password'), $account->fetchField('Account_Level'));
  53. } else {
  54. return null;
  55. }
  56. }
  57.  
  58. /**
  59. * encrypt a string or password
  60. *
  61. * @param null $text default encrypts the password otherwise decrypts the string
  62. * @return string returns the encrypted string/password.
  63. */
  64. public function encrypt($text = null)
  65. {
  66. if (is_null($text)) {
  67. return md5(sha1(crc32(md5(base64_decode($this->password . SALT)) . SALT)));
  68. } else {
  69. return md5(sha1(crc32(md5(base64_decode($text . SALT)) . SALT)));
  70. }
  71.  
  72. }
  73.  
  74. /**
  75. * log the account and validate it.
  76. *
  77. * @static
  78. * @param null $username the username to log in with.
  79. * @param null $password the password to log in with
  80. * @return bool true if its a valid login.
  81. */
  82. public static function validate($username = null, $password = null)
  83. {
  84. if (!is_null($username) && !is_null($password)) {
  85. $account = self::read($username);
  86.  
  87. if (!is_null($account)) {
  88. if (strcmp($account->encrypt(), $account->encrypt($password)) == 0) {
  89.  
  90. Register::set('account', $account, true);
  91. Register::set('public key', KEY, true);
  92. return true;
  93. }
  94. return false;
  95. }
  96. } else {
  97. if (is_null(Register::get('public key', true))) {
  98. return false;
  99. } else {
  100. if (strcmp(Register::get('public key', true), KEY) == 0)
  101. return true;
  102. return false;
  103. }
  104. }
  105. }
  106.  
  107.  
  108. public function getClearence()
  109. {
  110. return $this->clearence;
  111. }
  112.  
  113.  
  114. public function getPassword()
  115. {
  116. return $this->password;
  117. }
  118.  
  119.  
  120.  
  121. public function getUsername()
  122. {
  123. return $this->username;
  124. }
  125. */
  126.  
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement