-
Notifications
You must be signed in to change notification settings - Fork 402
LDAP auth #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
LDAP auth #212
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,17 +308,51 @@ function fillSessionInfo() { | |
// Check that user/password is correct. | ||
function check_auth($login,$password) | ||
{ | ||
$hash = sha1($password.$login.$GLOBALS['salt']); | ||
if ($login==$GLOBALS['login'] && $hash==$GLOBALS['hash']) | ||
$success = False; | ||
if ('LDAP'==$GLOBALS['config']['auth_backend']) | ||
{ | ||
// use LDAP authentification. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: "authentification " -> "authentication" |
||
// Needs global configuration; | ||
// auth_backend = LDAP | ||
// ldaphost: LDAP hostname | ||
// ldapport: LDAP port | ||
// ldaprdntpl: user RDN template (%login% replaced by actual login) | ||
$success = check_auth_ldap($login, $password); | ||
} | ||
else | ||
{ | ||
$hash = sha1($password.$login.$GLOBALS['salt']); | ||
$success = ($login==$GLOBALS['login'] && $hash==$GLOBALS['hash']); | ||
} | ||
if ($success) | ||
{ // Login/password is correct. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update this line again, as now it doesn't only mean that the username and password are correct, but can mean that the LDAP login is valid. Suggested change: |
||
fillSessionInfo(); | ||
fillSessionInfo(); | ||
logm('Login successful'); | ||
return True; | ||
} | ||
logm('Login failed for user '.$login); | ||
return False; | ||
} | ||
|
||
// Check user/password with ldap server. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace "user" by "username". |
||
function check_auth_ldap($login,$password) | ||
{ | ||
// check invalid login/password | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace "login" by "username". |
||
if (empty($login) or empty($password) or preg_match('/[^a-zA-Z]/',$login)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a general quesion (I'm not familiar with the LDAP specs): why the |
||
logm('Invalid login or password'); | ||
return False; | ||
} | ||
$userrdn = str_replace("%login%", $login, $GLOBALS['config']['ldaprdntpl']); | ||
$ldapconn = ldap_connect($GLOBALS['config']['ldaphost'], $GLOBALS['config']['ldapport']); | ||
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); | ||
if ($ldapconn) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rewrite the if/else statement like this:
|
||
{ | ||
return (ldap_bind($ldapconn, $userrdn, $password)); | ||
} | ||
else logm('LDAP connection failed'); | ||
return False; | ||
} | ||
|
||
// Returns true if the user is logged in. | ||
function isLoggedIn() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update this comment, as now it doesn't only mean checking that the username and password are correct, but can mean verifying the LDAP login is valid. Suggested change:
"Check that the username/password combination or LDAP credentials are valid"