Wt: Wt::Auth::HashFunction Class Reference

Wt 3.3.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Member Functions
Wt::Auth::HashFunction Class Reference
Authentication module (Wt::Auth)

An abstract cryptographic hash function interface. More...

`#include <Wt/Auth/HashFunction>`

Inheritance diagram for Wt::Auth::HashFunction:
[legend]

List of all members.

## Public Member Functions
virtual | ~HashFunction ()
| Destructor.
virtual std::string | name () const =0
| Returns the name for this hash function.
virtual std::string | compute (const std::string &msg, const std::string &salt) const =0
| Computes the hash of a message + salt.
virtual bool | verify (const std::string &msg, const std::string &salt, const std::string &hash) const
| Verifies a message with the salted hash.

## Detailed Description

An abstract cryptographic hash function interface.

A cryptographic hash function computes a hash value from a message, for which it is hard to guess another message that generates the same hash.

These hash functions are intended for short messages, typically passwords or random tokens, and thus not suitable for computing the hash value of a large document.

When used for passwords, to avoid dictionary attacks, the hash functions accept also a random salt which is hashed together with the password. Not all hash functions are adequate for passwords hashes.

## Member Function Documentation

virtual std::string Wt::Auth::HashFunction::compute | ( | const std::string & | msg,
|  | const std::string & | salt
| ) |  | const`[pure virtual]`

Computes the hash of a message + salt.

The message is usually an ASCII or UTF-8 string.

The `salt` and the computed hash are encoded in printable characters. This is usually ASCII-encoded(as for the UNIX crypt() functions)or could be Base64-encoded.

Implemented in Wt::Auth::BCryptHashFunction, Wt::Auth::SHA1HashFunction, and Wt::Auth::MD5HashFunction.

virtual std::string Wt::Auth::HashFunction::name | ( |  | ) | const`[pure virtual]`

Returns the name for this hash function.

This should return a (short) name that uniquely identifies this hash function.

Implemented in Wt::Auth::BCryptHashFunction, Wt::Auth::SHA1HashFunction, and Wt::Auth::MD5HashFunction.

bool Wt::Auth::HashFunction::verify | ( | const std::string & | msg,
|  | const std::string & | salt,
|  | const std::string & | hash
| ) |  | const`[virtual]`

Verifies a message with the salted hash.

The base implementation will recompute the hash of the message with the given salt, and compare it to the `hash`.

Some methods however store the salt and additional settings in the `hash`, and this information is thus needed to verify the message hash.

Reimplemented in Wt::Auth::BCryptHashFunction.

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator