Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Login implements Authenticable {
- private $user;
- private $password;
- function __construct(array $attributes) {
- if (!isset($atributes['user'])) {
- throw new LoginException('User name expected');
- }
- $this->user = $attributes['user'];
- $this->password = isset($attributes['password']) ? $attributes['password'] : '';
- }
- function authenticate(MyPDO $db) {
- try {
- $sql = "SELECT id, name, password, surname FROM user WHERE nickname=?";
- $select = $db->prepare($sql);
- $select->execute(array($this->user));
- $profile = $select->fetch(\PDO::FETCH_OBJ);
- if (($profile === false) ||
- (crypt($this->password, $profile->password) !== $profile->password)) {
- throw new LoginException('User not found');
- }
- $_SESSION['id'] = $profile->id;
- $_SESSION['name'] = $profile->name;
- $_SESSION['surname'] = $profile->surname;
- $_SESSION['error'] = array();
- } catch (\PDOException $e) {
- throw new LoginException(__METHOD__ . $e->getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement