Class UserPasswordAuthenticator
- Namespace
- MailFathom.Infrastructure.Security.Passwords
- Assembly
- MailFathom.Infrastructure.dll
Judges the credential a request presented against the passwords this deployment stores for its users.
public sealed class UserPasswordAuthenticator
- Inheritance
-
UserPasswordAuthenticator
- Inherited Members
Remarks
Every rule worth asserting about HTTP Basic on this deployment lives here rather than in the handler above it: what a readable credential is, what a username folds to, how many attempts a source gets, what the stored record is compared with, and what a refusal is allowed to distinguish. A test reaches all of it without a request pipeline.
One failure path. An unknown username, a wrong password, a credential somebody disabled, and a credential whose user record has since been removed all return CredentialUnrecognized, and each of them spends one key derivation before it does. That is what DecoyPasswordHash is for: a username that resolves nothing would otherwise be refused in the time of one indexed read, and a client timing the difference would be enumerating the accounts this deployment holds. The last of the four cases cannot arise while the credential row's foreign key stands — removing a user removes their credentials with them — and it is refused along the same path anyway rather than being modelled as something that could be reported.
Cheap refusals first. The header is read, bounded, and folded into a canonical username before the bound is consulted, and the bound is consulted before any password is verified. An unauthenticated caller therefore cannot make this process perform a deliberately expensive derivation by writing a malformed header, and cannot make it perform an unbounded number of them by writing well-formed ones — a verification permit is taken before the derivation, on a ceiling the whole surface shares as well as one each axis holds, so five hundred requests issued at once meet that ceiling however many different usernames they name. What a right password costs is nothing: the reservation is returned unspent, because the credential travels on every request and a bound a correct password paid into would bound the user's own traffic rather than anybody's guessing. Only a wrong password spends the guessing allowance, and it holds what it spent for a minute.
Nothing written down is the credential. Neither the returned result nor anything logged on the way to it carries the presented password, the presented username, or the stored hash. What a record names is the credential's identifier where one was established safely, and the surface and the rejection where it was not.
Constructors
- UserPasswordAuthenticator(IUserCredentialStore, IPasswordHasher, PasswordAttemptLimiter, DecoyPasswordHash, ILogger<UserPasswordAuthenticator>)
Initializes a new user password authenticator.
Methods
- AuthenticateAsync(string, string?, string?, int, int, CancellationToken)
Judges the credential an
Authorizationheader carried.