Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function checkLogin($secret_key) {
- global $db;
- if (isset($_COOKIE['HORBLECOOKIE'])) :
- $data = explode('-', $_COOKIE['HORBLECOOKIE']);
- $_SESSION['uid'] = $data[1];
- $_SESSION['hash'] = $data[0];
- endif;
- $this->uid = $_SESSION['uid'];
- $this->hashkey = $_SESSION['hash'];
- if (!isset($this->uid) || !isset($this->hashkey)) {
- $this->logout();
- } else {
- $check = sha1($this->uid . $this->ip . $secret_key);
- if ($check != $this->hashkey) {
- $this->logout();
- } else {
- $query = $db->execute("SELECT * FROM users WHERE id='".$this->uid."'") or die(mysql_error());
- $userarray = $db->fetchassoc($query);
- if ($db->numrows($query) == 0) {
- $this->logout();
- }
- foreach($userarray as $key=>$value) {
- $user->$key = $value;
- }
- $this->logged_in = 1;
- return $user;
- }
- }
- }
- public function login($email, $password, $keepmein, $secret_key) {
- global $msgError;
- $this->email = clean($email, 1, 1, 3);
- $this->password = clean($password, 1 , 1, 0);
- if (empty($this->email) || empty($this->password)) {
- $msgError = "You have left empty fields!";
- return;
- }
- $result = User::confirmUserPass($this->email, $this->password);
- if ($result == 1 || $result == 3) {
- $msgError = "Please enter valid email and password.";
- return;
- } elseif ($result == 2) {
- $msgError = "Your user account has not been activated yet!";
- return;
- }
- if (empty($msgError)) {
- $this->userinfo = User::getUserInfo('users', 'email', $this->email);
- $this->id = $_SESSION['uid'] = $this->userinfo['id'];
- $this->hashkey = $_SESSION['hash'] = sha1($this->id . $this->ip . $secret_key);
- User::updateUserField('users', 'email', $this->email, "last_login", $this->time);
- User::updateUserField('users', 'email', $this->email, "ip", $this->ip);
- User::updateUserField('users', 'email', $this->email, "times_logged", $this->userinfo['times_logged'] + 1);
- if ($keepmein) {
- setcookie("HORBLECOOKIE", $this->hashkey . '-' . $this->id, $this->time + COOKIE_EXPIRE);
- }
- $this->logged_in = 1;
- return true;
- } else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement