PHP Class Airship\Engine\Security\Authentication

Airship gear: Authentication Covers both short-term authentication (current browsing session) and optional long-term authentication (i.e. "remember me" cookies).
Show file Open project: paragonie/airship

Protected Properties

Property Type Description
$db Airship\Engine\Contract\DBInterface
$dummyHash string
$tableConfig array $this->tableConfig contains all of the selectors (table/column names) used in the internal queries. This is useful if you need to change the queries in a Gear without rewriting them.

Public Methods

Method Description
__construct ( EncryptionKey $key, Airship\Engine\Contract\DBInterface $db = null ) Authentication constructor.
createAuthToken ( integer $userId ) : string Create, store, and return a token for long-term authentication
createHash ( HiddenString $password ) : string Generate a hash of a password
login ( string $username, HiddenString $password ) : boolean | integer Verifies that the password is valid for a given user account. Returns false whether or not the user name is valid and attempts to minimize leaking that information through timing side-channels.
loginByToken ( string $token = '' ) : integer Authenticate a user by a long-term authentication token (e.g. a cookie).
migrateImportedHash ( HiddenString $password, HiddenString $passwordHash, array $userData = [] ) : boolean Attempt to login against a migrated hash. If successful, replace the existing password hash with an encrypted hash of the original password.
rotateToken ( string $token, integer $userId ) : mixed Replace the existing long-term authentication cookie
setDatabase ( Airship\Engine\Contract\DBInterface $db ) : self Sets the database handler.
setDatabaseByKey ( string $dbIndex = '' ) : self Set the database of this authentication library to match this
setLongTermSelectorField ( string $field ) : self Sets the column name used to reference the "selector" component of the long-term authentication token.
setLongTermValidatorField ( string $field ) : self Sets the column name used to reference the "validator" component of the long-term authentication token.
setPasswordField ( string $field ) : self Sets the column name used to reference the password hash stored in the database, for SQL queries.
setTable ( string $table ) : self Change the table used for
setUserIdField ( string $field ) : self Sets the column name used to reference the primary key (userid)
setUsernameField ( string $field ) : self Sets the column name used to reference the user selector, for SQL queries.

Protected Methods

Method Description
registerMigrations ( ) Overloadable.

Method Details

__construct() public method

Authentication constructor.
public __construct ( EncryptionKey $key, Airship\Engine\Contract\DBInterface $db = null )
$key EncryptionKey
$db Airship\Engine\Contract\DBInterface

createAuthToken() public method

Create, store, and return a token for long-term authentication
public createAuthToken ( integer $userId ) : string
$userId integer
return string (to store in a cookie, for example)

createHash() public method

Generate a hash of a password
public createHash ( HiddenString $password ) : string
$password HiddenString
return string

login() public method

Verifies that the password is valid for a given user account. Returns false whether or not the user name is valid and attempts to minimize leaking that information through timing side-channels.
public login ( string $username, HiddenString $password ) : boolean | integer
$username string
$password HiddenString
return boolean | integer

loginByToken() public method

Authenticate a user by a long-term authentication token (e.g. a cookie).
public loginByToken ( string $token = '' ) : integer
$token string
return integer int

migrateImportedHash() public method

Attempt to login against a migrated hash. If successful, replace the existing password hash with an encrypted hash of the original password.
public migrateImportedHash ( HiddenString $password, HiddenString $passwordHash, array $userData = [] ) : boolean
$password HiddenString
$passwordHash HiddenString
$userData array
return boolean

registerMigrations() protected method

Overloadable.
protected registerMigrations ( )

rotateToken() public method

Replace the existing long-term authentication cookie
public rotateToken ( string $token, integer $userId ) : mixed
$token string
$userId integer
return mixed

setDatabase() public method

Sets the database handler.
public setDatabase ( Airship\Engine\Contract\DBInterface $db ) : self
$db Airship\Engine\Contract\DBInterface
return self ($this)

setDatabaseByKey() public method

Set the database of this authentication library to match this
public setDatabaseByKey ( string $dbIndex = '' ) : self
$dbIndex string
return self ($this)

setLongTermSelectorField() public method

Sets the column name used to reference the "selector" component of the long-term authentication token.
public setLongTermSelectorField ( string $field ) : self
$field string
return self ($this)

setLongTermValidatorField() public method

Sets the column name used to reference the "validator" component of the long-term authentication token.
public setLongTermValidatorField ( string $field ) : self
$field string
return self ($this)

setPasswordField() public method

Sets the column name used to reference the password hash stored in the database, for SQL queries.
public setPasswordField ( string $field ) : self
$field string
return self ($this)

setTable() public method

Change the table used for
public setTable ( string $table ) : self
$table string
return self ($this)

setUserIdField() public method

Sets the column name used to reference the primary key (userid)
public setUserIdField ( string $field ) : self
$field string
return self ($this)

setUsernameField() public method

Sets the column name used to reference the user selector, for SQL queries.
public setUsernameField ( string $field ) : self
$field string
return self ($this)

Property Details

$db protected property

protected DBInterface,Airship\Engine\Contract $db
return Airship\Engine\Contract\DBInterface

$dummyHash protected property

protected string $dummyHash
return string

$tableConfig protected property

$this->tableConfig contains all of the selectors (table/column names) used in the internal queries. This is useful if you need to change the queries in a Gear without rewriting them.
protected array $tableConfig
return array