aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers/usersController.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-01-12 03:10:31 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-01-12 03:10:31 +0100
commitd58886a937cbe425163526fc2ba3d2a118602035 (patch)
tree4769024f513d927c45fe3a6475e8dcdf92f01d0f /app/Controllers/usersController.php
parent43f1b227b459f8edade9d551164c18f56cfa1925 (diff)
Implémentation de l'indentification par mot de passe
Implémentation de https://github.com/marienfressinaud/FreshRSS/issues/104
Diffstat (limited to 'app/Controllers/usersController.php')
-rw-r--r--app/Controllers/usersController.php26
1 files changed, 22 insertions, 4 deletions
diff --git a/app/Controllers/usersController.php b/app/Controllers/usersController.php
index 8954c845d..cb5ebd209 100644
--- a/app/Controllers/usersController.php
+++ b/app/Controllers/usersController.php
@@ -21,18 +21,20 @@ class FreshRSS_users_Controller extends Minz_ActionController {
if (!function_exists('password_hash')) {
include_once(LIB_PATH . '/password_compat.php');
}
- $passwordHash = password_hash($passwordPlain, PASSWORD_BCRYPT); //A bit expensive, on purpose
+ $passwordHash = password_hash($passwordPlain, PASSWORD_BCRYPT, array('cost' => 8)); //This will also have to be computed client side on mobile devices, so do not use a too high cost
$passwordPlain = '';
+ $passwordHash = preg_replace('/^\$2[xy]\$/', '\$2a\$', $passwordHash); //Compatibility with bcrypt.js
$this->view->conf->_passwordHash($passwordHash);
}
- $mail = Minz_Request::param('mail_login', false);
- $this->view->conf->_mail_login($mail);
+ $email = Minz_Request::param('mail_login', false);
+ $this->view->conf->_mail_login($email);
$ok &= $this->view->conf->save();
$email = $this->view->conf->mail_login;
Minz_Session::_param('mail', $email);
+ Minz_Session::_param('passwordHash', $this->view->conf->passwordHash);
if ($email != '') {
$personaFile = DATA_PATH . '/persona/' . $email . '.txt';
@@ -89,10 +91,25 @@ class FreshRSS_users_Controller extends Minz_ActionController {
$ok &= !file_exists($configPath);
}
if ($ok) {
+
+ $passwordPlain = Minz_Request::param('new_user_passwordPlain', false);
+ $passwordHash = '';
+ if ($passwordPlain != '') {
+ Minz_Request::_param('new_user_passwordPlain'); //Discard plain-text password ASAP
+ $_POST['new_user_passwordPlain'] = '';
+ if (!function_exists('password_hash')) {
+ include_once(LIB_PATH . '/password_compat.php');
+ }
+ $passwordHash = password_hash($passwordPlain, PASSWORD_BCRYPT, array('cost' => 8));
+ $passwordPlain = '';
+ }
+ if (empty($passwordHash)) {
+ $passwordHash = '';
+ }
+
$new_user_email = filter_var($_POST['new_user_email'], FILTER_VALIDATE_EMAIL);
if (empty($new_user_email)) {
$new_user_email = '';
- $ok &= Minz_Configuration::authType() !== 'persona';
} else {
$personaFile = DATA_PATH . '/persona/' . $new_user_email . '.txt';
@unlink($personaFile);
@@ -102,6 +119,7 @@ class FreshRSS_users_Controller extends Minz_ActionController {
if ($ok) {
$config_array = array(
'language' => $new_user_language,
+ 'passwordHash' => $passwordHash,
'mail_login' => $new_user_email,
);
$ok &= (file_put_contents($configPath, "<?php\n return " . var_export($config_array, true) . ';') !== false);