Add User::authenticate()
This commit is contained in:
parent
90a8ae2cb8
commit
483603e77c
1 changed files with 50 additions and 1 deletions
|
@ -1,22 +1,71 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file src/Model/User.php
|
||||
* @brief This file includes the User class with user related database functions
|
||||
*/
|
||||
|
||||
namespace Friendica\Model;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBM;
|
||||
use dba;
|
||||
|
||||
require_once 'boot.php';
|
||||
require_once 'plugin.php';
|
||||
require_once 'include/plugin.php';
|
||||
|
||||
/**
|
||||
* @brief This class handles User related functions
|
||||
*/
|
||||
class User
|
||||
{
|
||||
public static function authenticate($user_info, $password)
|
||||
{
|
||||
if (is_object($user_info)) {
|
||||
$user = (array) $user_info;
|
||||
} elseif (is_int($user_info)) {
|
||||
$user = dba::select('user',
|
||||
['uid', 'password'],
|
||||
[
|
||||
'uid' => $user_info,
|
||||
'blocked' => 0,
|
||||
'account_expired' => 0,
|
||||
'account_removed' => 0,
|
||||
'verified' => 1
|
||||
],
|
||||
['limit' => 1]
|
||||
);
|
||||
} elseif (is_string($user_info)) {
|
||||
$user = dba::fetch_first('SELECT `uid`, `password`
|
||||
FROM `user`
|
||||
WHERE (`email` = ? OR `username` = ? OR `nickname` = ?)
|
||||
AND `blocked` = 0
|
||||
AND `account_expired` = 0
|
||||
AND `account_removed` = 0
|
||||
AND `verified` = 1
|
||||
LIMIT 1',
|
||||
$user_info,
|
||||
$user_info,
|
||||
$user_info
|
||||
);
|
||||
} else {
|
||||
$user = $user_info;
|
||||
}
|
||||
|
||||
if (!DBM::isResult($user) || !isset($user['uid']) || !isset($user['password'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$password_hashed = hash('whirlpool', $password);
|
||||
|
||||
if ($password_hashed !== $user['password']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user['uid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $uid user to remove
|
||||
* @return void
|
||||
|
|
Loading…
Reference in a new issue