MySQL 8.3.0
Source Code Documentation
HttpAuthBackendHtpasswd Class Reference

hashed key store. More...

#include <http_auth_backend.h>

Inheritance diagram for HttpAuthBackendHtpasswd:
[legend]

Public Types

using key_type = std::string
 
using value_type = std::string
 
using cache_type = std::string
 
using iterator = std::map< key_type, value_type >::iterator
 iterator More...
 
using const_iterator = std::map< key_type, value_type >::const_iterator
 const iterator More...
 

Public Member Functions

std::error_code from_file (const std::string &filename)
 replace cache with content from file. More...
 
std::error_code from_stream (std::istream &is)
 replace cache with content of input-stream. More...
 
void to_stream (std::ostream &os)
 write cache content to output-stream. More...
 
size_t erase (const key_type &username)
 remove username from credential cache. More...
 
void set (const key_type &username, const value_type &authdata)
 set username and password in cache. More...
 
iterator find (const key_type &username)
 find username in cache. More...
 
const_iterator find (const key_type &username) const
 find username in cache. More...
 
iterator end () noexcept
 end iterator. More...
 
const_iterator end () const noexcept
 const end iterator. More...
 
iterator begin () noexcept
 begin iterator. More...
 
const_iterator begin () const noexcept
 const begin iterator. More...
 
std::error_code authenticate (const key_type &username, const value_type &authdata) override
 validate user and authdata against backend. More...
 
- Public Member Functions inherited from HttpAuthBackend
 HttpAuthBackend ()=default
 
 HttpAuthBackend (const HttpAuthBackend &)=default
 
 HttpAuthBackend (HttpAuthBackend &&)=default
 
HttpAuthBackendoperator= (const HttpAuthBackend &)=default
 
HttpAuthBackendoperator= (HttpAuthBackend &&)=default
 
virtual ~HttpAuthBackend ()=0
 destructor. More...
 

Private Member Functions

std::error_code from_stream_ (std::istream &is)
 

Static Private Member Functions

static std::string hash_password (const std::string &password)
 Calculate hash of plain-text password. More...
 

Private Attributes

bool is_file_ {false}
 
std::string filename_
 
FileModified file_meta_
 
std::map< key_type, value_typecredentials_
 
std::map< key_type, cache_typecredentials_cache_
 

Detailed Description

hashed key store.

  • each line contains username and auth-data, separated by colon
  • auth-data should be based on PHC

PHC : $<id>[$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]]

id name supported
1 md5_crypt never
2 bcrypt never
2a bcrypt no
2b bcrypt no
5 sha256_crypt yes
6 sha512_crypt yes
pbkdf2-sha256 pkbdf2_sha256 no
pbkdf2-sha512 pkbdf2_sha512 no
scrypt scrypt no
argon2 argon2 no
bcrypt bcrypt no
See also
https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md

Member Typedef Documentation

◆ cache_type

◆ const_iterator

◆ iterator

◆ key_type

using HttpAuthBackendHtpasswd::key_type = std::string

◆ value_type

Member Function Documentation

◆ authenticate()

std::error_code HttpAuthBackendHtpasswd::authenticate ( const key_type username,
const value_type authdata 
)
overridevirtual

validate user and authdata against backend.

Returns
error
Return values
falseno authentication error

Implements HttpAuthBackend.

◆ begin() [1/2]

const_iterator HttpAuthBackendHtpasswd::begin ( ) const
inlinenoexcept

const begin iterator.

◆ begin() [2/2]

iterator HttpAuthBackendHtpasswd::begin ( )
inlinenoexcept

begin iterator.

◆ end() [1/2]

const_iterator HttpAuthBackendHtpasswd::end ( ) const
inlinenoexcept

const end iterator.

◆ end() [2/2]

iterator HttpAuthBackendHtpasswd::end ( )
inlinenoexcept

end iterator.

◆ erase()

size_t HttpAuthBackendHtpasswd::erase ( const key_type username)
inline

remove username from credential cache.

◆ find() [1/2]

iterator HttpAuthBackendHtpasswd::find ( const key_type username)
inline

find username in cache.

◆ find() [2/2]

const_iterator HttpAuthBackendHtpasswd::find ( const key_type username) const
inline

find username in cache.

◆ from_file()

std::error_code HttpAuthBackendHtpasswd::from_file ( const std::string &  filename)

replace cache with content from file.

◆ from_stream()

std::error_code HttpAuthBackendHtpasswd::from_stream ( std::istream &  is)

replace cache with content of input-stream.

Returns
error-code
Return values
falsewhen no error happened

◆ from_stream_()

std::error_code HttpAuthBackendHtpasswd::from_stream_ ( std::istream &  is)
private

◆ hash_password()

std::string HttpAuthBackendHtpasswd::hash_password ( const std::string &  password)
staticprivate

Calculate hash of plain-text password.

The hash generated by this function should be used at http basic authentication to speed up verification of the transferred credentials against account information stored in passwd file. There are no direct requirement how the hash should be calculated. Currently it uses following formula: HASH=SHA256(SHA256(plain-text-password)).

◆ set()

void HttpAuthBackendHtpasswd::set ( const key_type username,
const value_type authdata 
)
inline

set username and password in cache.

if username exists in cache, overwrite entry with password, otherwise create new entry for username

◆ to_stream()

void HttpAuthBackendHtpasswd::to_stream ( std::ostream &  os)

write cache content to output-stream.

Member Data Documentation

◆ credentials_

std::map<key_type, value_type> HttpAuthBackendHtpasswd::credentials_
private

◆ credentials_cache_

std::map<key_type, cache_type> HttpAuthBackendHtpasswd::credentials_cache_
private

◆ file_meta_

FileModified HttpAuthBackendHtpasswd::file_meta_
private

◆ filename_

std::string HttpAuthBackendHtpasswd::filename_
private

◆ is_file_

bool HttpAuthBackendHtpasswd::is_file_ {false}
private

The documentation for this class was generated from the following files: