use Friendica\Core\NotificationsManager;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
+use Friendica\Model\User;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Network\HTTPException\ForbiddenException;
$user = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
- $encrypted = hash('whirlpool', trim($password));
// allow "user@server" login (but ignore 'server' part)
$at = strstr($user, "@", true);
if (($addon_auth['authenticated']) && (count($addon_auth['user_record']))) {
$record = $addon_auth['user_record'];
} else {
- // process normal login request
- $r = q(
- "SELECT * FROM `user` WHERE (`email` = '%s' OR `nickname` = '%s')
- AND `password` = '%s' AND NOT `blocked` AND NOT `account_expired` AND NOT `account_removed` AND `verified` LIMIT 1",
- dbesc(trim($user)),
- dbesc(trim($user)),
- dbesc($encrypted)
- );
- if (DBM::is_result($r)) {
- $record = $r[0];
+ $user_id = User::authenticate(trim($user), trim($password));
+ if ($user_id) {
+ $record = dba::select('user', [], ['uid' => $user_id], ['limit' => 1]);
}
}
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Database\DBM;
+use Friendica\Model\User;
require_once 'include/security.php';
require_once 'include/datetime.php';
}
} else {
session_unset();
- if (x($_POST, 'password') && strlen($_POST['password'])) {
- $encrypted = hash('whirlpool', trim($_POST['password']));
- } else {
- if ((x($_POST, 'openid_url')) && strlen($_POST['openid_url']) ||
- (x($_POST, 'username')) && strlen($_POST['username'])) {
+ if (
+ !(x($_POST, 'password') && strlen($_POST['password']))
+ && (
+ x($_POST, 'openid_url') && strlen($_POST['openid_url'])
+ || x($_POST, 'username') && strlen($_POST['username'])
+ )
+ ) {
+ $noid = Config::get('system', 'no_openid');
- $noid = Config::get('system', 'no_openid');
+ $openid_url = trim(strlen($_POST['openid_url']) ? $_POST['openid_url'] : $_POST['username']);
- $openid_url = trim((strlen($_POST['openid_url']) ? $_POST['openid_url'] : $_POST['username']));
+ // validate_url alters the calling parameter
- // validate_url alters the calling parameter
- $temp_string = $openid_url;
+ $temp_string = $openid_url;
- // if it's an email address or doesn't resolve to a URL, fail.
- if ($noid || strpos($temp_string, '@') || !validate_url($temp_string)) {
- $a = get_app();
- notice(t('Login failed.') . EOL);
- goaway(System::baseUrl());
- // NOTREACHED
- }
+ // if it's an email address or doesn't resolve to a URL, fail.
- // Otherwise it's probably an openid.
- try {
- require_once('library/openid.php');
- $openid = new LightOpenID;
- $openid->identity = $openid_url;
- $_SESSION['openid'] = $openid_url;
- $_SESSION['remember'] = $_POST['remember'];
- $openid->returnUrl = System::baseUrl(true) . '/openid';
- goaway($openid->authUrl());
- } catch (Exception $e) {
- notice(t('We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID.') . '<br /><br >' . t('The error message was:') . ' ' . $e->getMessage());
- }
+ if ($noid || strpos($temp_string, '@') || !validate_url($temp_string)) {
+ $a = get_app();
+ notice(t('Login failed.') . EOL);
+ goaway(System::baseUrl());
// NOTREACHED
}
+
+ // Otherwise it's probably an openid.
+
+ try {
+ require_once('library/openid.php');
+ $openid = new LightOpenID;
+ $openid->identity = $openid_url;
+ $_SESSION['openid'] = $openid_url;
+ $_SESSION['remember'] = $_POST['remember'];
+ $openid->returnUrl = System::baseUrl(true) . '/openid';
+ goaway($openid->authUrl());
+ } catch (Exception $e) {
+ notice(t('We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID.') . '<br /><br >' . t('The error message was:') . ' ' . $e->getMessage());
+ }
+ // NOTREACHED
}
if (x($_POST, 'auth-params') && $_POST['auth-params'] === 'login') {
if ($addon_auth['authenticated'] && count($addon_auth['user_record'])) {
$record = $addon_auth['user_record'];
} else {
-
- // process normal login request
-
- $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey`
- FROM `user` WHERE (`email` = '%s' OR `nickname` = '%s')
- AND `password` = '%s' AND NOT `blocked` AND NOT `account_expired` AND NOT `account_removed` AND `verified` LIMIT 1",
- dbesc(trim($_POST['username'])),
- dbesc(trim($_POST['username'])),
- dbesc($encrypted)
- );
- if (DBM::is_result($r)) {
- $record = $r[0];
+ $user_id = User::authenticate(trim($_POST['username']), trim($_POST['password']));
+ if ($user_id) {
+ $record = dba::select('user', [], ['uid' => $user_id], ['limit' => 1]);
}
}
use Friendica\Core\PConfig;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
+use Friendica\Model\User;
require_once 'include/group.php';
$newpass = $_POST['password'];
$confirm = $_POST['confirm'];
- $oldpass = hash('whirlpool', $_POST['opassword']);
$err = false;
if ($newpass != $confirm) {
// check if the old password was supplied correctly before
// changing it to the new value
- $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user()));
- if ($oldpass != $r[0]['password']) {
+ if (User::authenticate(intval(local_user()), $_POST['opassword'])) {
notice(t('Wrong password.') . EOL);
$err = true;
}
if ($email != $a->user['email']) {
$email_changed = true;
// check for the correct password
- $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user()));
- $password = hash('whirlpool', $_POST['mpassword']);
- if ($password != $r[0]['password']) {
+ if (!User::authenticate(intval(local_user()), $_POST['mpassword'])) {
$err .= t('Wrong Password') . EOL;
$email = $a->user['email'];
}
use Friendica\Core\Config;\r
use Friendica\Core\PConfig;\r
use Friendica\Database\DBM;\r
+use Friendica\Model\User;\r
use dba;\r
\r
require_once 'include/dba.php';\r
\r
$aUser = dba::select('user', ['uid', 'password'], ['nickname' => $sUser], ['limit' => 1]);\r
if (DBM::is_result($aUser)) {\r
- $uid = $aUser['uid'];\r
- $Error = $aUser['password'] != hash('whirlpool', $aCommand[3]);\r
+ $uid = User::authenticate($aUser, $aCommand[3]);\r
+ $Error = $uid === false;\r
} else {\r
$this->writeLog(LOG_WARNING, 'user not found: ' . $sUser);\r
$Error = true;\r