summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkarel.wintersky <karel.wintersky@gmail.com>2015-09-12 07:03:09 +0300
committerkarel.wintersky <karel.wintersky@gmail.com>2015-09-12 07:03:09 +0300
commit7f39b3bbba4111f8a8bfd0516aad192bb3a76157 (patch)
tree3ab765d952da892ac78047f837ba361674f38751
parent6149801261f9cd3bdcb52d53a178f2702b7d19f7 (diff)
downloadPHPAuth-7f39b3bbba4111f8a8bfd0516aad192bb3a76157.zip
PHPAuth-7f39b3bbba4111f8a8bfd0516aad192bb3a76157.tar.gz
PHPAuth-7f39b3bbba4111f8a8bfd0516aad192bb3a76157.tar.bz2
fixed PHPDocs, + two functions
added functions: `getSessionHash()` -- Get current session hash, return string `comparePasswords(int $userid, string $testpassword)` -- Compare $testpassword with password stored in DB for this $userid, return bool changed visibility of `isEmailTaken()` function to public.
-rwxr-xr-xauth.class.php40
1 files changed, 37 insertions, 3 deletions
diff --git a/auth.class.php b/auth.class.php
index acd2793..cf9edcf 100755
--- a/auth.class.php
+++ b/auth.class.php
@@ -449,7 +449,7 @@ class Auth
* @return boolean
*/
- private function isEmailTaken($email)
+ public function isEmailTaken($email)
{
$query = $this->dbh->prepare("SELECT * FROM {$this->config->table_users} WHERE email = ?");
$query->execute(array($email));
@@ -463,8 +463,9 @@ class Auth
/**
* Adds a new user to database
- * @param string $email
- * @param string $password
+ * @param string $email -- email
+ * @param string $password -- password
+ * @param array $params -- additional params
* @return int $uid
*/
@@ -612,6 +613,7 @@ class Auth
* Creates an activation entry and sends email to user
* @param int $uid
* @param string $email
+ * @param string $type
* @return boolean
*/
@@ -1199,4 +1201,36 @@ class Auth
public function isLogged() {
return (isset($_COOKIE[$this->config->cookie_name]) && $this->checkSession($_COOKIE[$this->config->cookie_name]));
}
+
+ /**
+ * Returns current session hash
+ * @return string
+ */
+ public function getSessionHash(){
+ return $_COOKIE[$this->config->cookie_name];
+ }
+
+ /**
+ * Compare user's password with given password
+ * @param int $userid
+ * @param string $password_for_check
+ * @return bool
+ */
+ public function comparePasswords($userid, $password_for_check)
+ {
+ $query = $this->dbh->prepare("SELECT password FROM {$this->config->table_users} WHERE id = ?");
+ $query->execute(array($userid));
+
+ if ($query->rowCount() == 0) {
+ return false;
+ }
+
+ $data = $query->fetch(\PDO::FETCH_ASSOC);
+
+ if (!$data) {
+ return false;
+ }
+
+ return password_verify($password_for_check, $data['password']);
+ }
}