passwd

Library for UNIX-style password hashing.

Basic example of password hashing:

const salt = SHA512Crypt.genSalt();
// Result looks something like "$6$/CrouvED7qMJ/IbD"
auto crypted = "hunter2".crypt(salt);
// Result looks something like "$6$/CrouvED7qMJ/IbD$w2auDz2o61BBLowCbYbO.AIsM5XxSPME3PW2b7P.3qamDP5v4aSwyBPLDKolI/rBjTTGDIhUfUsszNv/DOy0B."

The interface to each algorithm is a struct with static members, as below:

struct CryptAlgo
{
	/// Length in bytes of a binary digest
	enum kDigestLength;
	/// Maximum length needed for output of genSalt()
	enum kMaxSaltStrLength;
	/// Maximum length needed for output of crypt()
	enum kMaxCryptStrLength;

	/// Generate a good salt for this algorithm
	static string genSalt();

	/// Generate a good salt for this algorithm and write to an output range
	static void genSalt(Out)(ref Out output) if (isOutputRange!(Out, char));
}

Modules

bcrypt
module passwd.bcrypt

Niels Provos' and David Mazières' bcrypt, a crypt(3) algorithm based on Bruce Schneier's Blowfish cipher

bcrypt_test
module passwd.bcrypt_test
Undocumented in source.
exception
module passwd.exception
Undocumented in source.
md5
module passwd.md5

Poul-Henning Kamp's MD5 crypt(3) algorithm

md5_test
module passwd.md5_test
Undocumented in source.
securewipe
module passwd.securewipe
Undocumented in source.
sha
module passwd.sha

Ulrich Drepper's SHA-based crypt(3) algorithms, as specified here: https://akkadia.org/drepper/SHA-crypt.txt

sha_test
module passwd.sha_test
Undocumented in source.
test
module passwd.test
Undocumented in source.
util
module passwd.util
Undocumented in source.

Public Imports

std.typecons
public import std.typecons : Flag, No, Yes;

Members

Aliases

CryptAlgos
alias CryptAlgos = AliasSeq!(MD5Crypt, Bcrypt, SHA256Crypt, SHA512Crypt)

All supported crypt(3) algorithms

Functions

canCryptTo
bool canCryptTo(const(char)[] password, const(char)[] crypted)

Test a password against the given crypt(3) string

crypt
char[] crypt(const(char)[] password, const(char)[] salt)
void crypt(const(char)[] password, Out output, const(char)[] salt, Flag!"writeSalt" write_salt)
void crypt(const(char)[] password, Out output, const(CryptPieces) salt_data, Flag!"writeSalt" write_salt)

Hash password according to salt

Manifest constants

kMaxCryptStrLength
enum kMaxCryptStrLength;

Maximum size needed for any crypt() result

kMaxSaltStrLength
enum kMaxSaltStrLength;

Maximum size needed for any genSalt() result

Meta