HOW TO ADD ANOTHER MEMBER FIELD AS A LOGIN CREDENTIAL?

Discussion in 'General Chat' started by petermguwata, Jul 14, 2017.

  1. petermguwata

    petermguwata New Member

    I'm working on a project and i would like to include another credential to the login in page.

    E.g.
    1. email or username
    2. companyid (this one I've added it as a user field in the admin page)
    3. password

    (in short I NEED the user has to fill in all three to login in the front end)

    HOW DO I LINK THE DATABASE IN /front/login.php TO SPECIFY AND VALIDATE THE NEW MEMBER FIELD (companyid) AS A CREDENTIAL?:(
  2. Dayir_A.

    Dayir_A. Staff Member

    Hello @petermguwata,

    There is no much things in login.php file. In order to add new field in login page you should first add this field in login.tpl (template file).
    This file's location is in /templates/YOUR_TEMPLATE_NAME/login.tpl
    if no such file present, then it's in /templates/_common/logint.tpl

    After that you should edit /includes/classes/ia.core.users.php file getAuth method.
    As you can see it accepts userId, password.
    In the body of this method you should change the condition to this:
    PHP:
    $condition = '(u.`username` = :username OR u.`email` = :email) AND u.`password` = :password AND u.`company_id` = :company';
    $this->iaDb->bind($condition, [
        'username' => preg_replace('/[^a-zA-Z0-9.@_-]/', '', $user),
        'email' => $user,
        'password' => $this->encodePassword($password),
        'company' => (int)$_POST['company_id'],
    ]);
    Also you can edit getAuth, so it will get companyId as parameter.
    Hope this helps

    Thanks.
    petermguwata likes this.
  3. petermguwata

    petermguwata New Member

    Hi @Dayir_A.

    Thank you for the support the code works fine just after changing the code from:
    PHP:
    $condition = '(u.`username` = :username OR u.`email` = :email) AND u.`password` = :password AND u.`company_id` = :company';
    $this->iaDb->bind($condition, [
        'username' => preg_replace('/[^a-zA-Z0-9.@_-]/', '', $user),
        'email' => $user,
        'password' => $this->encodePassword($password),
        'company' => (int)$_POST['company_id'],
    ]);
    to:
    PHP:
    $condition = '(u.`username` = :username OR u.`email` = :email) AND u.`password` = :password AND u.`companyid` = :companyid';
                $this->iaDb->bind($condition, [
                    'username' => preg_replace('/[^a-zA-Z0-9.@_-]/', '', $user),
                    'email' => $user,
                    'password' => $this->encodePassword($password),
                    'companyid' => $_POST['companyid'],
                ]);
    Once again many thanks for the priceless support.

    Warmest Regards!
  4. Dayir_A.

    Dayir_A. Staff Member

Share This Page