Password-based authentication
Name
Password-based authentication
Summary
A subject proves they own a claimed identity by providing a correct identifier, such as a username or email address, and the corresponding password. This pattern relies on the assumption that only the actual owner of the claimed identity knows the correct password.
Parent
Problem
- See Authentication
Solution
Roles
- Subject (: Entity) wants to login into the
System - Enforcer (: Enforcement point) ensures the requested action is only performed if the
Subjectis successfully authenticated, this entity must be incorporated into theSystem - Verification manager (: Entity) is responsible to collect the inputs necessary to verify a
Subject's password - Comparator (: Decision point) compares the hash value of the received password against that provided by the
Password store - Hasher (: Cryptographic primitive) calculates the hash value for a given input
- Verification manager + Comparator + Hasher <- Authentication.Verifier
- Password store (: Storage) keeps track of the hash values corresponding to each registered identity
- Password store <- Authentication.Evidence provider
- Pepper store (: Storage) keeps track of the pepper value(s) used by the system
- Encrypter (: Cryptographic primitive) encrypts a given data element using a given cryptographic key
- System (: Entity) contains the business logic corresponding to the requested action
- Registrar (: Entity) handles the
Subject's registration and forwards the evidence to thePassword store - Resetter (: Entity handles the reset of a
Subject's credential in case the current credential is lost - Password policy (: Information point) contains the rules any password should satisfy in order to be valid, e.g. minimum and maximum number of characters
- Hash manager (: Entity) is responsible to collect the necessary inputs to calculate the hash value for a new password
- SRNG (: Cryptographic primitive) a cryptographically secure random number generator
Actions
- action (: Action) that the
Subjectwants to perform. For this pattern the requested action is most often a login request.- action <- Authentication.action
- verify (: Action) the provided credential against the appropriate evidence
- get_pwd (: Action) retrieve the password as known by the
System- get_pwd <- Authentication.get_evidence
- get_pepper (: Action) retrieve the pepper value (for the provided id)
- calculate_hash (: Action) calculate the hash value of the provided data element(s)
- encrypt (: Action) compute the ciphertext corresponding to the given key and plaintext
- compare (: Action) check whether the provided data elements are identical to each other
- register (: Action) add a new credential to the system to allow future authentication
- add (: Action) add new evidence corresponding to a credential
- reset (: Action) change the current credential to the newly provided one
- update (: Action) update the credential, and corresponding evidence, to the newly provided values
- check (: Action) check whether the provided password is valid with respect to the system's password policy
- next (: Action) retrieve the a new randomly generated value
Data elements
- id (: Data) identifies the identity claimed by the
Subject- id <- Authentication.principal
- Tags: Identifier, Untampered
- pwd (: Data) serves as the
Subject's proof-of-ownership of the claimed identity- id + password <- Authentication.credential
- Tags: Secret, Untampered
- hash(x, y) (: Data) the hash value calculated from the concatenation of elements
xandy- Tags: Untampered
- {x}_k (: Data) the ciphertext resulting from encrypting
xusing keyk- Tags: Untampered
- stored_pwd (: Data) a
Subject's password as it stored persistently after registration- stored_pwd <- Authentication.evidence
- salt (: Data) random value to ensure the hash value of each password is unique
- Tags: Untampered
- pepper (: Data) random value used as key to encrypt password hash values before storage as additional protection against an attacker cracking the passwords
- Tags: Secret, Untampered
- reply (: Data) from the
Systemtriggered by the requested action (optional)- token <- Authentication.reply
- error (: Data) message informing the receiving some check failed or a request could not be successfully executed
- args (: Data) any additional arguments the
Subjectcan provide as part of an action request (optional)
Behaviour
A subject logging into a system and obtaining a token proving successful authentication boils down to nine interactions.
- The
Subjectprovides theEnforcerwith its identifier and password as part of its action request. - The
Enforcerforwards the identifier and password to theVerification managerfor verification and blocks the login request awaiting an answer. - The
Verification managerrequests the stored hash value and salt from thePassword store. - The
Verification managerreceives the requested hash value and salt from thePassword store. - The
Verification managerforwards the received salt and password to theHasher. - The
Hashercalculates the requested hash value and transmits the result back to theVerification manager. - The
Verification managerrequests the correct pepper value from thePepper store. - The
Pepper storereplies with the corresponding pepper value. - The
Verification managerforwards the received pepper along with the password's hash value to theEncrypter. - The
Encrypterencrypts the received hash value using the pepper as cryptographic key and replies the resulting ciphertext to theVerification manager. - The
Verification managerforwards the received ciphertext and the stored hash value to theComparatorfor comparison. - The
Comparatorchecks whether the newly calculated ciphertext is identical to the one that was retrieved from thePassword storeand informs theVerification managerof the result of the verification. - The
Verification managerforwards the result of the password verification to theEnforcer. - If the
Enforcerreceives confirmation that the provided password is correct, theEnforcerforwards the login action request to theSystem. Otherwise theSubjectis informed of the failure to login. - Optionally, the
Systemreplies to theSubjectafter receiving and/or executing the action request. This reply does not need to pass through theEnforcer.
Role considerations
Password store
Specialisation of Authentication.Evidence provider
Passwords are typically stored in persistent storage, e.g. a database containing account information or a file containing valid user accounts. Passwords should at all times be stored in hashed form.4 See the section on hashing algorithms for more information.
Resource usage (Enforcer, Verification manager, Password store, Comparator, Hasher)
Specialisation of Authentication.Resource usage
In addition to prevent that an attacker can disrupt the authentication mechanism by using excessive resources, further measures should also be taken to protect the accounts associated the principals themselves. More specifically, it is advised to temporarily lock an account after a certain number of failed login attempts in order to prevent any further attempts.2 This prevents that an attacker can try many different passwords in a short period of time. The exact lockout period as well as the allowed number of failed login attempts depend on the context of the system at hand, and should strike a balance between usability and security.
Password policy
The security of a password-based authentication mechanism depends largely on the password remaining secret to anyone other than the Subject. Therefore, it should be hard for other parties to guess a Subject's password through manual or automated means. A good password policy for choosing passwords, either by the Subject or the Registrar, can make it more challenging for attackers to guess correct passwords.2 6 Note that this policy also applies to passwords intended for limited use, e.g. a default account password set by the Registrar which the Subject is meant to change when logging in for the first time.
The most common advise for good for password policies:
- Set a minimum password length of 8 characters2 1 8
- Set a maximum length of 64 characters to 128 characters 2 1 8
- At the minimum allow all ASCII characters as well as white space2 1 5
- Block common and previously breached passwords 1 2 8
The appropriate maximum length for passwords may depend on the hashing algorithm used, it is advised to consult the documentation of the used library for details.
In case a Subject provides a password that does not comply to the password policy at hand the Subject should merely be informed of this. The system should never (silently) modify the provided password to comply with its policy. For example, if a Subject provides a password during registration that exceeds the maximum length it should not be automatically truncated.2 1
Some widespread practices are not good practice for password policies and should be avoided:
- Do not impose any further composition rules aside from the above common composition rules, for example do not require a certain number of non-alphanumeric characters or capital letters. Such additional rules decrease the number of possible passwords, making it easier for an attacker to guess a correct one.
- Do not arbitrarily, e.g. periodically, require subjects to change their password.1 5 Such measures tend to drive (human)
Subjects to choose related, predictable passwords5, e.g. the new password is a minor variation of the previous one. Only force password changes in case of password leaks or when (part of) the system was compromised.2
Finally, if the Registrar selects the (initial) password, ensure this is randomly generated and not based on some (easily) obtainable information such as the Subjects username, the Subject's social security number or a serial number associated with the Subject.
Hashing algorithm (Hasher, Password store)
Passwords should be stored in the Password store in such a way that an attacker cannot obtain them even if the Password store is compromised4. To this end passwords should be hashed before they are stored, such that even if an attacker obtains the hash value it is not possible to (easily) derive the original password.4 1
One should use well-known cryptographic libraries that provide support for modern hashing algorithms (e.g. Argon2id, bcrypt, and PBKDF2).4 1 The References section contains some pointers to possible libraries.
While designing a system it should always be considered that it is likely that the used hashing algorithm has to updated at some point in the future.4 It is advisable to design your system in such a manner to make such updates as easy as possible. Some possible strategies to deal with such updates are described by OWASP.
Password salting (Hasher, SRNG, Password store)
In order to make cracking a password hash more difficult, a random string, unique for each Subject, typically called a salt, should be added before calculating the password's hash value.4 1 The addition of such a salt is intended to ensure that the hash value for each Subject is unique irrelevant whether they use the same password (in multiple applications). Consequently, an attacker has to compute the hash value for each possible password individually instead of computing them all once and simply comparing the resulting hash values to those obtained from the application. Note, as the salt is needed each time a login request is received from a Subject, they are generally stored in plain text alongside the corresponding hash value in the Password store.
If one uses a modern hashing algorithm, as advised above, a salt is typically automatically generated and added during the calculation of a password's hash value. In case the used library allows for some configuration of the salt, one should take care its minimal length is 16 characters as advised by OWASP2 or 32 bits as advised by NIST1. If one uses a library that does not automatically add a salt, a cryptographically secure generation function always be used to generate salts.
Password peppering (Encrypter, SRNG, Pepper store)
In order to further hinder attackers cracking any obtained hash values they can be peppered before storing them.4 The pepper is a random string that, similar to the above salt, should be generated using a cryptographically secure random generator where the advised minimal length is 32 characters4 or 112 bits1.
The same pepper is used for all password entries in the Password store, therefore the pepper should be treated as a cryptographic key and kept confidential at all times. Consequently, the pepper should not be added as input to the hash value calculation as this may leak its value. Instead the pepper should be used as key to compute an HMAC or symmetrically encrypted ciphertext of the hash value of the salted password. Furthermore, the pepper should not be stored in Password store but kept somewhere else to preserve its secrecy, e.g in a hardware security module.
As with any used cryptographic key, the pepper might have to be changed at some point in the future. Therefore, any system using password peppering should be designed to facilitate pepper rotation.
Ciphertext comparison (Comparator)
The Comparator should use a secure comparison function to compare the calculated ciphertext with the stored one.2 A secure comparison function should enforce a maximum input length to protect against denial of service attacks, and return in constant time to protect against timing attacks.
Subject registration (Registrar)
Specialisation of Authentication.Subject registration
The goal of the registration procedure is that upon completion, the Password store contains the identifier, hash value of the salted password, and salt. Furthermore, the Subject should possess its identifier and password upon completion. These data elements can be determined in one of three ways:
- the
Subjectprovides its identifier as well as password - the
Subjectprovides its identifier, theRegistrarselects a password and provides this to theSubject - the
Registrarselects both identifier and password for theSubject
In the Subject provides any input data, i.e. identity and/or password, additional security measures should be considered to ensure secure processing of this data.
Note that in this pattern, the Registrar is always responsible for constructing the evidence, i.e. hash value, based the selected or received password. One should never rely on the Subject to provide the evidence corresponding to its password.
Password change (Password store)
Specialisation of Authentication.Credential change
Before a Subject can change its password it should be explicitly (re-)authenticated by requiring it to provide the current password.2 7 Other proofs of authentication, e.g. a valid (session) token, should not be considered sufficient to perform such a sensitive operation. This way, even when attackers obtain a valid token they cannot permanently lock legitimate Subjects out of their accounts by changing the passwords.
Password reset (Resetter)
Specialisation of Authentication.Credential reset
A Subject that requests to reset its password should be explicitly authenticated through a side-channel before being allowed to do so.3 Such side-channel can, for example, consist of
- a URL token communicated via email or
- a PIN send to the
Subjectvia SMS.
The methods available for the system at hand depend on the information that is gathered during registration.
The token used during side-channel authentication must be chosen such that it is not easily guessable or enumerated by an attacker. In general it is advised to use a cryptographically secure random number generator to generate sufficiently long and random tokens.3
Note, that the result of the side-channel authentication should not leak information about whether the provided information was valid, as this would allow an attacker to enumerate existing accounts. For instance, say that a Subject is required to provide an email address to initiate a password reset. If the system would present an error message in case the email address does not match a known Subject, an attacker could use this to determine for which email addresses an account exists in the system. This information could be useful in further, more targeted attacks on these accounts. Instead, the system should show a generic message, for example that a URL token was emailed to the provided email address, while actually sending this token only if the provided email address was known by the system.
Finally, a password reset mechanism as described here should always be used instead of "password hints" to help a Subject to remember his or her password.1
Error messages (Enforcer, Resetter)
Specialisation of Authentication.Error messages
Any error message shown to the Subject should be sufficiently generic as not to reveal whether is was caused by
- an unknown
id; or - an incorrect
pwd.
For example, the error return when authentication failed should be something like "Incorrect username and/or password".
Log authentication failures (Verification manager)
Specialisation of Authentication.Log authentication failures
Data considerations
Selection of credential and evidence
Specialisation of Authentication.Selection of credential and evidence
The credential from the parent pattern is split into two parts, an identifier and a password, where the latter is crucial for security. Note that a password is considered a credential of the type something you know, with the underlying assumption that only the Subject knows the correct password for the given identifier. As evidence the hash value of the password is used, which will be kept in the password store.
The correctness of the authentication mechanism should never rely on the secrecy of the identifier provided by the Subject. For example, identifiers such as email addresses, usernames, or hostnames are often rather easy to obtain by an attacker. Yet, it is advised to take measures to prevent that an attacker can easily obtain an overview of (all) valid identifiers for the system, e.g. by keeping error messages sufficiently generic. Having an overview of valid identifiers might help an attacker in mounting a successful attack against the system.
id
Specialisation of Authentication.principal
pwd
Specialisation of Authentication.credential
stored_pwd
Specialisation of Authentication.evidence
Hash values and ciphertext (hash(x, y), {x}_k, salt, pepper)
The password verification process involves calculating a hash value and cipher text to compare against the stored evidence, i.e. stored_pwd. For the integrity of the verification process it is important that an attacker cannot tamper with the results, or inputs of these calculations. In case any of these data elements are transmitted over an uncontrolled channel additional precautions to detect any tampering are necessary. Furthermore, the salt and pepper values are also stored in their respective storage entities and measures are needed to detect any unauthorised changes. Finally, the pepper should be treated as a cryptographic key and should be kept confidential at all times.
Password scope
Specialisation of Authentication.Credential scope
It is generally impossible to prevent a Subject from reusing a password (on other systems), even if the password is generated by the Registrar. Instead Subject can be made aware that they should avoid using the same password for different accounts. Note that checking a password against lists of commonly used or breached passwords, as suggested in Password policy, does avoid Subjects such predictable passwords.
Implementations
None
Xet Storage Details
- Size:
- 30.4 kB
- Xet hash:
- 43d7e538c4641e1f0eaba3ab032869475e8aa34d861c4e6e068adb6be28d5523
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.