Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 508153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:52:40+00:00 2026-05-13T06:52:40+00:00

So I am using Zend_Auth to authenticate users of my website. Currently they are

  • 0

So I am using Zend_Auth to authenticate users of my website. Currently they are only able to log in with their email as login but I would like to enable them to log in also with their username.

Here is some code:

        // prepare adapter for Zend_Auth
        $adapter = new Zend_Auth_Adapter_DbTable($this->_getDb());
        $adapter->setTableName('users');
        $adapter->setIdentityColumn('email');
        $adapter->setCredentialColumn('password_hash');
        $adapter->setCredentialTreatment('CONCAT(SUBSTRING(password_hash, 1, 40), SHA1(CONCAT(SUBSTRING(password_hash, 1, 40), ?)))');
        $adapter->setIdentity($request->getParam('email'));
        $adapter->setCredential($request->getParam('password'));

Notice the line:

        $adapter->setIdentityColumn('email');

How can I add also username there (column in the database called username, too)?

UPDATE:

This is how I solved this:

        $login = $request->getParam('email');
        $validator = new Zend_Validate_EmailAddress();
        if (false === $validator->isValid($login)) {
            $u = $this->_getTable('Users')->getSingleWithUsername($login);
            if (null === $u) {
                throw new Exception ('Invalid login and/or password');
            }
            $login = $u->email;
        }

        // prepare adapter for Zend_Auth
        $adapter = new Zend_Auth_Adapter_DbTable($this->_getDb());
        $adapter->setTableName('users');
        $adapter->setIdentityColumn('email');
        $adapter->setCredentialColumn('password_hash');
        $adapter->setCredentialTreatment('CONCAT(SUBSTRING(password_hash, 1, 40), SHA1(CONCAT(SUBSTRING(password_hash, 1, 40), ?)))');
        $adapter->setIdentity($login);
        $adapter->setCredential($request->getParam('password'));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:52:40+00:00Added an answer on May 13, 2026 at 6:52 am

    I deal with the same thing, and I handle it before Zend_Auth. I use a single user sign-in field and first check whether it’s an email address — if so, it’s converted to the appropriate username. Then, let Zend_Auth do its thing.

    This works well for me, although you’ll need to kinda switch it around, since you’re going the other way.

    i. Add a filter to your user sign-in field, like this:

    $user_field->addFilter('EmailToUsername');
    

    ii. The filter:

    <?php
    
    /**
     * Converts an email address to the username.
     */
    class Prontiso_Filter_EmailToUsername implements Zend_Filter_Interface
    {
      public function filter( $value )
      {
        if ( Zend_Validate::is($value, 'EmailAddress') ) {
    
          $user_table = new Users();
          $user = $user_table->findByEmail($value);
          if ( $user ) {
            return $user->username;
          }
        }
    
        /**
         * Nothing happened, so don't filter.
         */
        return $value;
      }
    }
    

    As for just changing a Zend_Auth setting instead, Zend_Auth doesn’t like either/or identity columns, so you’d have to write your own auth adapter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i'm using a simple Zend_Auth mechanism to ensure my users login before they
I am using Zend_Auth_Adapter_Ldap to authenticate users for my Zend Framework based intranet website.
I use Zend_Auth to authenticate users and then store their details in the default
I'm using Zend_Auth to store session values after login. My question is: let's say
i'm using Zend_Mail to send out an email from Aruba PEC. $config = array('auth'=>'login',
Here is what happens to some users of IE8 when using the website i
I have a registration form and I am using zend_auth for my login, below
How to create reasonable expression to store password in database using Doctrine and Zend_Auth::setCredentialTreatment()
I have a Zend Framework project using version 1.10.8 with Doctrine 1.2.4.I use Zend_Auth
I'm currently using Zend Framework 2 beta for on PHP 5.4.4 to develop a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.