private function userFromCookie() { $cookie = SC::getCookie("sc_auth"); if (!$cookie) { return false; } $cookie_array = explode("||", base64_decode($cookie)); //echo (var_dump($cookie_array)); $user_id = $cookie_array[0]; $cookie_auth_token = $cookie_array[1]; $sql = "SELECT user_password, user_email from users WHERE user_id=" . $user_id; $db = new SCDB(); $result = $db->queryArray($sql); if (sizeof($result)) { //$auth_token = $this->createAuthToken($user_id, $result[0]["user_password"]); $auth_token = md5($result[0]["user_email"] . $result[0]["user_password"]); if (strcmp($cookie_auth_token, $auth_token) === 0) { $this->setSessionUser($user_id, SCUser::saltPassword($result[0]["user_password"])); return $this->getSessionUser(); } } return false; }
public function create($password = null, $confirm_password = null) { if ($this->existing) { throw new Exception("This is an existing user... you can not create an existing user", 400); } if (!$password || !$confirm_password) { throw new Exception("Password and Password Confirmation are required", 400); } if (strcmp($password, $confirm_password) !== 0) { throw new Exception("Password and Password Confirmation do not match", 400); } $create_array = $this->toArray(true); $create_array["user_password"] = SC::dbString(SCUser::saltPassword($password), true); $create_array["user_createdate"] = SC::dbDate(); $db = new SCDB(); $db->insertFromArray($create_array, "users"); $user_id = mysql_insert_id($db->conn); if ($user_id) { $user = new SCUser($user_id); $this->fromArray($user->toArray()); } else { throw new UserException(mysql_error($db->conn)); } return $this; }