Zend Framework Salting Example

I am new to the Zend framework and want to create an application with fairly strong password protection. I am trying to follow user instructions regarding stick salting, but still no luck. I installed my adapter for the database and the table (as described in the documentation on the Zend Framework website, but it does not seem to complete the example (or I'm not familiar enough!) I started with:

$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter, 
            'users', 
            'username',
'password',                                         "MD5(CONCAT('".Zend_Registry::get('staticSalt')."', ?, password_salt))"
    );

But from here, what is done with salt passwords? I just need an example, and I'll be far away! Does anyone have an example or point me in the right direction?

Many thanks!

+3
source share
2 answers

Zend Framework ( )

Zend Framework

+2

:

/**
 * Authenticate user with specified identity and credential
 *
 * most used case is authenticate user inline in script
 *
 * @param string $identity
 * @param string $credential
 * @return Zend_Auth_Result
 */
public function authenticate ($identity, $credential)
{
    $auth = Zend_Auth::getInstance();
    $adapter = $this->getAdapter();
    $adapter->setIdentity($identity)
            ->setCredential(self::passwordHash($credential));

    $config = Singular_Runtime::extract('config');
    $isActiveCol = $config->resources->auth->columns->is_active;
    $isActiveAllowVal = $config->resources->auth->is_active->allow_value;

    /**
     * @see APPLICATION_PATH/configs/application.ini -> resources.auth
     */
    if (null != $isActiveCol && null != $isActiveAllowVal) {
        $adapter->getDbSelect()->where("{$isActiveCol} = ?", $isActiveAllowVal);
    }

    Singular_Event::dispatch('beforeAuth', array(
        'auth' => $auth, 'adapter' => $adapter
    ));

    $result = $auth->authenticate($adapter);

    if ($result->isValid()) {
        $auth->getStorage()->write($adapter->getResultRowObject());

        Singular_Event::dispatch('afterAuth', array(
            'auth' => $auth, 'adapter' => $adapter
        ));
    }

    return $result;
}

:

/**
 * Password hash generator
 *
 * @static
 * @param  string $password
 * @return string
 */
public static function passwordHash ($password)
{
    $password = strtolower($password);

    return md5(
        str_repeat(
            md5($password) . strrev($password) . sha1($password),
            strlen($password)
        )
    );
}
+1

Source: https://habr.com/ru/post/1749899/


All Articles