Skip to content

Commit

Permalink
OTP feature removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Simounet committed May 11, 2023
1 parent 84e520e commit 4e58044
Show file tree
Hide file tree
Showing 33 changed files with 27 additions and 4,216 deletions.
3 changes: 1 addition & 2 deletions Configuration.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class Configuration extends MysqlEntity{
'synchronisationType' => 'auto',
'theme' => 'marigolds',
'root' => '',
'cryptographicSalt' => '',
'otpEnabled' => 0
'cryptographicSalt' => ''
);

function __construct(){
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ Le dépot [Leed market](https://github.com/Leed-market) contient tous les plugin
- Javascript : JQuery (http://www.jquery.com)
- Moteur template : RainTPL (https://github.com/feulf/raintpl)
- Parseur RSS : SimplePie (http://simplepie.org)
- QR Code : PhpQrCode (https://sourceforge.net/projects/phpqrcode)
- OTP : OtPhp (https://github.com/lelag/otphp)
- Php GD : LibGD (https://libgd.github.io/)


Expand Down Expand Up @@ -134,8 +132,6 @@ The [Leed-market](https://github.com/Leed-market) repository contains all the pl
- Javascript: JQuery ( http://www.jquery.com )
- Template Engine: RainTPL ( https://github.com/feulf/raintpl )
- RSS Parser: SimplePie ( http://simplepie.org )
- QR Code: PhpQrCode (https://sourceforge.net/projects/phpqrcode)
- OTP: OtPhp (https://github.com/lelag/otphp)
- Php GD : LibGD (https://libgd.github.io/)


Expand Down Expand Up @@ -205,6 +201,4 @@ El repositorio [Leed market](https://github.com/Leed-market) contiene todos los
- Javascript : JQuery (http://www.jquery.com)
- PHP Template : RainTPL (https://github.com/feulf/raintpl)
- RSS parser : SimplePie (http://simplepie.org)
- QR Code : PhpQrCode (https://sourceforge.net/projects/phpqrcode)
- OTP : OtPhp (https://github.com/lelag/otphp)
- Php GD : LibGD (https://libgd.github.io/)
57 changes: 6 additions & 51 deletions User.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@

class User extends MysqlEntity{

const OTP_INTERVAL = 30;
const OTP_DIGITS = 8;
const OTP_DIGEST = 'sha1';

protected $id,$login,$password,$otpSecret;
protected $id;
protected $login;
protected $password;
protected $TABLE_NAME = 'user';
protected $object_fields =
array(
'id'=>'key',
'login'=>'string',
'password'=>'string',
'otpSecret'=>'string',
'password'=>'string'
);

protected $object_fields_uniques =
Expand All @@ -35,42 +32,9 @@ function setId($id){
$this->id = $id;
}

function isOtpSecretValid($otpSecret) {
// Teste si la longueur est d'au moins 8 caractères
// et en Base32: [A-Z] + [2-7]
return is_string($otpSecret) && preg_match('/^[a-zA-Z2-7]{8,}$/', $otpSecret);
}

protected function getOtpControler() {
return new \OTPHP\TOTP($this->otpSecret, array('interval'=>self::OTP_INTERVAL, 'digits'=>self::OTP_DIGITS, 'digest'=>self::OTP_DIGEST));
}

function getOtpKey() {
$otp = $this->getOtpControler();
return str_pad($otp->now(), $otp->digits, '0', STR_PAD_LEFT);
}

function exist($login,$password,$salt='',$otpEntered=Null){
function exist($login,$password,$salt=''){
$userManager = new User();
$user = $userManager->load(array('login'=>$login,'password'=>User::encrypt($password,$salt)));

if (false!=$user) {
$otpSecret = $user->otpSecret;

global $configurationManager;
switch (True) {
case !$configurationManager->get('otpEnabled'):
case empty($otpSecret) && empty($otpEntered):
// Pas d'OTP s'il est désactivé dans la configuration où s'il n'est pas demandé et fourni.
return $user;
}
$otp = $user->getOtpControler();
if ($otp->verify($otpEntered) || $otp->verify($otpEntered, time()-10)) {
return $user;
}
}

return false;
return $userManager->load(array('login'=>$login,'password'=>User::encrypt($password,$salt)));
}

static function get($login){
Expand Down Expand Up @@ -210,17 +174,8 @@ function setPassword($password,$salt=''){
$this->password = User::encrypt($password,$salt);
}

function getOtpSecret(){
return $this->otpSecret;
}

function setOtpSecret($otpSecret){
$this->otpSecret = $otpSecret;
}

function resetPassword($resetPassword, $salt=''){
$this->setPassword($resetPassword, $salt);
$this->otpSecret = '';
$this->save();
}

Expand Down
1 change: 0 additions & 1 deletion about.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

require_once('header.php');

$tpl->assign('otpEnabled', $configurationManager->get('otpEnabled'));
$view = 'about';
require_once('footer.php');

Expand Down
21 changes: 1 addition & 20 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
$configurationManager->put('feedMaxEvents',$_['feedMaxEvents']);
$configurationManager->put('language',$_['ChgLanguage']);
$configurationManager->put('theme',$_['ChgTheme']);
$configurationManager->put('otpEnabled',$_['otpEnabled']);

if(trim($_['password'])!='') {
$salt = User::generateSalt();
Expand All @@ -138,16 +137,6 @@

}

# Modifications dans la base de données, la portée courante et la sesssion
# @TODO: gérer cela de façon centralisée
$otpSecret = $_['otpSecret'];
if ($myUser->isOtpSecretValid($otpSecret)) {
$userManager->change(array('login'=>$_['login'], 'otpSecret'=>$otpSecret),array('id'=>$myUser->getId()));
$myUser->setLogin($_['login']);
$myUser->setOtpSecret($otpSecret);
$_SESSION['currentUser'] = serialize($myUser);
}

header('location: ./settings.php#preferenceBloc');
break;

Expand Down Expand Up @@ -461,24 +450,16 @@
exit();
}
}else{
$isOtpEnabled = (bool) $configurationManager->get('otpEnabled');
if((!isset($_['login']) || empty($_['login']) || !is_string($_['login']))
|| (!isset($_['password']) || empty($_['password']) || !is_string($_['password']))
|| ($isOtpEnabled
&& (!isset($_['otp']) || empty($_['otp']) || !is_string($_['otp']))
)
) {
error_log("Leed: wrong login action detected");
header('location: ./?action=wrongLogin');
exit;
}
$salt = $configurationManager->get('cryptographicSalt');
if (empty($salt)) $salt = '';
if($isOtpEnabled) {
$user = $userManager->exist($_['login'],$_['password'],$salt,$_['otp']);
} else {
$user = $userManager->exist($_['login'],$_['password'],$salt);
}
$user = $userManager->exist($_['login'],$_['password'],$salt);
if($user==false){
error_log("Leed: wrong login for '".$_['login']."'");
header('location: ./?action=wrongLogin');
Expand Down
1 change: 0 additions & 1 deletion common.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
require_once('constant.php');
require_once('RainTPL.php');
require_once('i18n.php');
require_once('otphp/lib/otphp.php');
class_exists('Functions') or require_once('Functions.class.php');
class_exists('Plugin') or require_once('Plugin.class.php');
class_exists('MysqlEntity') or require_once('MysqlEntity.class.php');
Expand Down
2 changes: 0 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
$feedState = new Feed();
$tpl->assign('feedState',$feedState);
}
//afficher ou non le champ OTP
$tpl->assign('otpEnabled', $configurationManager->get('otpEnabled'));

$articleDisplayAuthor = $configurationManager->get('articleDisplayAuthor');
$articleDisplayDate = $configurationManager->get('articleDisplayDate');
Expand Down
20 changes: 0 additions & 20 deletions otphp/LICENCE

This file was deleted.

71 changes: 0 additions & 71 deletions otphp/README.markdown

This file was deleted.

74 changes: 0 additions & 74 deletions otphp/lib/hotp.php

This file was deleted.

Loading

0 comments on commit 4e58044

Please sign in to comment.