Forum

Welcome to ProjeQtOr new Forum. We migrated old forum to the new website.
You will find all your posts here, with your usual account.
Just one point : you’ll have to reinitialize your password. Use “Lost password” feature.

How to make usernam...
 
Notifications
Clear all

How to make username case insensitive ?

9 Posts
2 Users
0 Reactions
7,079 Views
Fathi Ben Nasr
(@fathibn)
Posts: 59
Active Member
Topic starter
 
[#5006]

Hi,
I have ProjeQtor connected to an Active Directory for user provisionning and authentication. When a user connects, it happens that sometimes he enters his username in lowercase/uppercase ending with two different users in the postgresql projeQtor database.
How can i prevent this, forcing all usernames to be upper/lowercase ?
TIA


 
Posted : 09 Mar 2018 15H11
(@babynus)
Posts: 14952
Member Admin
 

Hi,

This seems an issue.
There is no "way to avoid".
We'll have to provide a fix.

Ticket #3261 recorded


 
Posted : 09 Mar 2018 20H41
(@babynus)
Posts: 14952
Member Admin
 

Try this patch :
In /tool/loginCheck.php, replace line 80 from

    $user=new User();

to

    $user=new User();
    $paramLdap_allow_login=Parameter::getGlobalParameter('paramLdap_allow_login'); // If ldap is enabled, look for username without case sensitive, as it will be stored this way.
    if (isset($paramLdap_allow_login) and strtolower($paramLdap_allow_login)=='true') {
      $crit=array('name'=>strtolower($login));
      $users=$user->getSqlElementsFromCriteria($crit,true);
      if ( count($users)==1 ) {
        $user=$users[0];
      }
    }

 
Posted : 09 Mar 2018 21H07
Fathi Ben Nasr
(@fathibn)
Posts: 59
Active Member
Topic starter
 

Hello and thank you for submitting a patch promptly,

I have tried with my username which is uppercase. I removed the second user (myself in lowercase), applied the patch and logged in both with upper and lowercase username. I still have a new user created with the username lowercase. I think the patch will work for new users (not yet created before the patch or whom usernames are already lowercase). For those already in the users table, maybe we should add a check to see if the user already exists and then retain the case of the user present in database, like this:
compare strtolower(username provided) to strtolower(all users in database); if there is a match, retain the username_already_existing_in_the_database as the login_provided, for subsequent ldap queries, changing its case.
As ProjeQtor aims to be multilangual, I don't know how strtolower will behave when username is in some languages like cyrilic, chinease, hebrew or arabic in which there is no uppercase .

TIA
Fathi Ben Nasr


 
Posted : 10 Mar 2018 11H40
(@babynus)
Posts: 14952
Member Admin
 

Yes, this quick patch controls that name in lowercase does not exist as it it will create new user with lowaercase.
So existing dupplicates with uppercase will not be detected.

Here is the patch that will fit your need :

    $user=new User();
    $paramLdap_allow_login=Parameter::getGlobalParameter('paramLdap_allow_login'); // If ldap is enabled, look for username without case sensitive, as it will be stored this way.
    if (isset($paramLdap_allow_login) and strtolower($paramLdap_allow_login)=='true') {
      $critWhere="lower(name)='".strtolower($login)."'");
      $users=$user->getSqlElementsFromCriteria(null,true,$critWhere);
      if ( count($users)==1 ) {
        $user=$users[0];
      }
    }

 
Posted : 10 Mar 2018 13H51
Fathi Ben Nasr
(@fathibn)
Posts: 59
Active Member
Topic starter
 

Hello again,
Applied the second patch but had to revert back as no user could login to ProjeQtor, not even the local admin account.
TIA
Fathi Ben Nasr


 
Posted : 10 Mar 2018 15H22
(@babynus)
Posts: 14952
Member Admin
 

Sorry.
I posted the patch before testing.
The correct patch is :

    $user=new User();
    $paramLdap_allow_login=Parameter::getGlobalParameter('paramLdap_allow_login'); // If ldap is enabled, look for username without case sensitive, as it will be stored this way.
    if (isset($paramLdap_allow_login) and strtolower($paramLdap_allow_login)=='true') {
      $critWhere="lower(name)='".strtolower($login)."'";
      $users=$user->getSqlElementsFromCriteria(null,true,$critWhere);
      if ( count($users)==1 ) {
        $user=$users[0];
      }
    }

(remove the last penrenthesis on line 83)


 
Posted : 10 Mar 2018 15H41
Fathi Ben Nasr
(@fathibn)
Posts: 59
Active Member
Topic starter
 

Sorry, I should have noticed the unbalanced parentheses instead of blindly replying with No.

I applied this new patch and as cou can see from my postgresql log, here after, lowercase user is still created:
LOG: exécute pdo_stmt_0000000b: insert into audit ( sessionId , auditDay , idUser , userName , platform , browser , browserVersion , userAgent , connectionDateTime , lastAccessDateTime , duration , idle , requestRefreshParam , requestRefreshProject , requestDisconnection ) values ('ftf51cb7qq86ms2cg6njhidrn2', '20180310', '3', '39471N', 'Windows', 'Mozilla Firefox', '58.0', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0', '2018-03-10 15:11:48', '2018-03-10 15:11:48', '00:00:00', '0', '0', '0', '0')
LOG: exécute pdo_stmt_0000000a: insert into resource (isuser, name , fullName , email , idProfile , locked , isContact , isResource , idle , dontReceiveTeamMails , isLdap , apiKey ) values ('1', '39471n', 'FATHI BEN NASR', 'fathi.bennasr@sncft.com.tn', '5', '0', '1', '1', '0', '0', '1', '08195scarmbled280')
LOG: exécute pdo_stmt_00000021: insert into mail ( idUser , mailDateTime , mailTo , mailStatus , idle , mailTitle , mailBody ) values ('12', '2018-03-10 15:12', 'fathi.bennasr@sncft.com.tn', 'WAIT', '0', 'ProjeQtOr - Nouvel utilisateur', 'L''utilisateur ''39471n'' a été créé à partir de Ldap')
LOG: exécute pdo_stmt_0000002c: insert into alert ( idUser , alertType , alertInitialDateTime , alertDateTime , readFlag , idle , title , message ) values ('1', 'INFO', '2018-03-10 15:12:25', '2018-03-10 15:12:25', '0', '0', 'ProjeQtOr - Nouvel utilisateur', 'L''utilisateur ''39471n'' a été créé à partir de Ldap')
LOG: exécute pdo_stmt_00000031: insert into audit ( sessionId , auditDay , idUser , userName , platform , browser , browserVersion , userAgent , connectionDateTime , lastAccessDateTime , duration , idle , requestRefreshParam , requestRefreshProject , requestDisconnection ) values ('6n3evcn5lmt5gcvgn186qom734', '20180310', '12', '39471n', 'Windows', 'Mozilla Firefox', '58.0', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0', '2018-03-10 15:12:25', '2018-03-10 15:12:25', '00:00:00', '0', '0', '0', '0')


 
Posted : 10 Mar 2018 17H20
(@babynus)
Posts: 14952
Member Admin
 

The patch may not work if there already exists several users with same name (butwith different cases)


 
Posted : 10 Mar 2018 18H25
Share:

Scroll to Top