This topic is locked
[SOLVED]

Two-factor authentication

12/20/2021 7:03:36 AM
PHPRunner General questions
ffrinai author

Hi,
i have phprunner 10.5 enterprise build 37251.
I enable Two-factor authentication and it works fine with local users, but i have some users ldap autenticated with code in
before login:

global $conn;
$strSQLExists = "select * from utenti where username='" . $username . "'";
$rsExists = db_query($strSQLExists, $conn);
$data = db_fetch_array($rsExists);
if (!$data) {
$message = "account not exist.";
return false;
}
$_SESSION["ld"] = $data["ldap"];
$_SESSION["ldap"] = $data["ldap"];

if ($data["ldap"] == 'S') { //verify if ldap="S" <<<<<-------- (0)
if ($password != null && trim($password) != '') {
$ad = new adLDAPAuthentication(
array(
'account_suffix' => "MYDOMAIN.IT",
'base_dn' => "dc=MYDOMAIN,dc=IT",
'domaincontrollers' => array(
"192.168.1.xx", "192.168.1.xy"
)
)
);
$authenticated = $ad->authenticate($username, $password);

if ($authenticated) {
Security::loginAs($username, true); <<<<<<<-------------- (1)
header("Location: menu.php"); <<<<<<<---------------(2)
} else {
$message = "Login not valid.";
return false;
}
} else {
$message = "Login not valid/password wrong.";
return false;
}
} else { //ldap
return true;
}// end if field ldap


i have a fleld ldap (0) with "S" for ldap authentication and "N" for local authentication
with ldap authentication the authcode is not required, i think because (1) make login true and (2) redirect to menu.php !

may someone help me to request the authcode even in the case of ldap = "S" ?
Thanks

Fabio

Sergey Kornilov admin 12/26/2021

Since you are doing custom authentication then, I guess, you would need something custom for two-factor authentication as well. Not really sure what to suggest here.

ffrinai author 12/30/2021

I solved the problem by storing the password in the users table after authenticating with ldap

if ($authenticated) {

//Security::loginAs($username, true);<<<<<<<-------------- (1)
//header("Location: menu.php");<<<<<<<---------------(2)

$data2 = array();
$keyvalues2 = array();
$data2["Password"] = getPasswordHash($password);
$keyvalues2["Username"] = $username;
DB::Update("utenti", $data2, $keyvalues2);
$pageObject->hideItem("ldap_snippet");
return true;

} else {
$message = "Login not valid/password wrong.";
return false;
}

I realize it's not very elegant, but it works for me.
Fabio