コード例 #1
0
ファイル: Authorization.php プロジェクト: tniessen/tinyIt
 /**
  * Attempts to create an authorized session using given credentials.
  *
  * @param string $name
  * @param string $password
  *
  * @see Database\UsersTableAdapter::getUserByName
  * @see Cryptography::check
  */
 public static function login($name, $password)
 {
     $dbc = Application::dbConnection();
     $user = $dbc->users()->getUserByName($name);
     if (!$user) {
         return false;
     }
     $correctPassword = Cryptography::check($password, $user->password);
     if ($correctPassword) {
         $_SESSION['tiUserId'] = $user->id;
         $_SESSION['tiNonce'] = sha1(microtime(true));
         self::$userInfo = $user;
         return $user->id;
     } else {
         self::clearSessionData();
         self::$userInfo = null;
         return false;
     }
 }
コード例 #2
0
ファイル: UsersTableAdapter.php プロジェクト: tniessen/tinyIt
 /**
  * Adds a user.
  *
  * @param string $username
  * @param string $displayName
  * @param string $email
  * @param string $password
  * @return int
  * @throws \PDOException
  */
 public function addUser($username, $displayName, $email, $password)
 {
     $this->insert('name=?, name_lc=?, display_name=?, email=?, password=?, registered=' . time(), array($username, strtolower($username), $displayName, strtolower(trim($email)), \tniessen\tinyIt\Cryptography::hash($password)));
     return $this->dbc->lastInsertId();
 }