• Stars
    star
    287
  • Rank 138,917 (Top 3 %)
  • Language
    Go
  • License
    Other
  • Created over 9 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ”‘ Idiotproof golang password validation library inspired by Python's passlib

passlib for go

godocs.io Build status No modules 100% modules-free.

Python's passlib is quite an amazing library. I'm not sure there's a password library in existence with more thought put into it, or with more support for obscure password formats.

This is a skeleton of a port of passlib to Go. It dogmatically adopts the modular crypt format, which passlib has excellent documentation for.

Currently, it supports:

  • Argon2i
  • scrypt-sha256
  • sha512-crypt
  • sha256-crypt
  • bcrypt
  • passlib's bcrypt-sha256 variant
  • pbkdf2-sha512 (in passlib format)
  • pbkdf2-sha256 (in passlib format)
  • pbkdf2-sha1 (in passlib format)

By default, it will hash using scrypt-sha256 and verify existing hashes using any of these schemes.

Example Usage

There's a default context for ease of use. Most people need only concern themselves with the functions Hash and Verify:

// Hash a plaintext, UTF-8 password.
func Hash(password string) (hash string, err error)

// Verifies a plaintext, UTF-8 password using a previously derived hash.
// Returns non-nil err if verification fails.
//
// Also returns an upgraded password hash if the hash provided is
// deprecated.
func Verify(password, hash string) (newHash string, err error)

Here's a rough skeleton of typical usage.

import "gopkg.in/hlandau/passlib.v1"

func RegisterUser() {
  (...)

  password := get a (UTF-8, plaintext) password from somewhere

  hash, err := passlib.Hash(password)
  if err != nil {
    // couldn't hash password for some reason
    return
  }

  (store hash in database, etc.)
}

func CheckPassword() bool {
  password := get the password the user entered
  hash := the hash you stored from the call to Hash()

  newHash, err := passlib.Verify(password, hash)
  if err != nil {
    // incorrect password, malformed hash, etc.
    // either way, reject
    return false
  }

  // The context has decided, as per its policy, that
  // the hash which was used to validate the password
  // should be changed. It has upgraded the hash using
  // the verified password.
  if newHash != "" {
    (store newHash in database, replacing old hash)
  }

  return true
}

scrypt Modular Crypt Format

Since scrypt does not have a pre-existing modular crypt format standard, I made one. It's as follows:

$s2$N$r$p$salt$hash

...where N, r and p are the respective difficulty parameters to scrypt as positive decimal integers without leading zeroes, and salt and hash are base64-encoded binary strings. Note that the RFC 4648 base64 encoding is used (not the one used by sha256-crypt and sha512-crypt).

Licence

passlib is partially derived from Python's passlib and so maintains its BSD license.

ยฉ 2008-2012 Assurance Technologies LLC.  (Python passlib)  BSD License
ยฉ 2014 Hugo Landau <[email protected]>  BSD License

More Repositories

1

acmetool

๐Ÿ”’ acmetool, an automatic certificate acquisition tool for ACME (Let's Encrypt)
Go
2,015
star
2

service

โšก Easily write daemonizable services in Go
Go
500
star
3

acme.t

ACME automatic certificate acquisition tool. Repository has moved to:
70
star
4

ortega

Ortega FDK
C
56
star
5

portmap

๐Ÿšฅ Port mapping library for Go supporting NAT-PMP and UPnP
Go
33
star
6

kvmtest

An experimental VMM for KVM written in pure Python
Python
21
star
7

tftp2httpd

๐Ÿ“ Serve files over TFTP from HTTP.
Makefile
20
star
8

captcha

๐Ÿ‘“ Go CAPTCHA
Go
10
star
9

tn5250

VT terminal-based 5250 emulator (5250->xterm adapter) and library
C
10
star
10

kconfigreport

Reports of how the Linux kernel is configured by different distributions.
Python
9
star
11

madns

๐ŸŒ Authoritative DNS server engine for Go
Go
9
star
12

memu

ARMv8-M/Cortex-M emulator/simulator
C++
9
star
13

acmeapi

ACMEv2 client library for Go. See branch "new" for current version (gopkg.in/hlandau/acmeapi.v2)
Go
9
star
14

ncdocs

Various Namecoin-related documents
GCC Machine Description
7
star
15

ncdns.t

Namecoin to DNS bridge daemon. This repository has moved to
7
star
16

svcutils

โšก Utilities for writing services in Go
Go
7
star
17

configurable

๐Ÿ’พ Function-free golang integration nexus for configuration
Go
6
star
18

ircproto

IRC protocol client library and bot
Go
6
star
19

compex

โ„น๏ธ GCC/clang compiler plugins for the dumping of C++ type information in a machine-readable format
C++
6
star
20

parazmq

๐Ÿšง Pure Go implementation of ZMTP/3.0 (ZeroMQ's protocol) (*work in progress*)
Go
5
star
21

measurable

๐Ÿ“ˆ Function-free golang integration nexus for metrics
Go
4
star
22

specwriter

Writing natural-language technical specifications in Guile Scheme
Scheme
4
star
23

eddsa

๐Ÿ”‘ Structures for safe handling of Ed25519 keys
Go
4
star
24

ovmfvartool

Generate and dump OVMF_VARS.fd files to/from YAML
Python
4
star
25

easyconfig

๐Ÿ’พ Easy bindings for hlandau/configurable
Go
4
star
26

tags-active-demo

Demo program for use of memory tagging on POWER9 (Talos/Blackbird)
C
4
star
27

degoutils

๐Ÿšง Go utilities
Go
4
star
28

buildinfo

Go utilities for tracking build information
Go
3
star
29

nomadircd

๐Ÿšง IRC daemon written in Go. Rough.
Go
3
star
30

dht

๐Ÿšง BitTorrent Mainline DHT implementation (work in progress)
Go
3
star
31

expect-ct-lite

OpenSSL example code for Expect-CT Lite
C
2
star
32

winnmc

Don't use this
Batchfile
2
star
33

irc

An IRC client library for Go
Go
2
star
34

namesync

๐ŸŒ Synchronize the namecoin name database with a PostgreSQL database
Go
2
star
35

rilts

Repository-Integrated Licence Tracking Specification (RILTS)
Go
2
star
36

mnt-reform-freebsd

Scripts for MNT Reform FreeBSD enablement work
Shell
2
star
37

altirc

2
star
38

openssl-ddd

C
2
star
39

easymetric

๐Ÿ“ˆ Easy bindings for hlandau/measurable
Go
2
star
40

armparse

Python
2
star
41

tldinfo

JSON-formatted TLD information
Shell
2
star
42

condorcet

Condorcet voting for Go
Go
2
star
43

js.Context

Go-style context for Node.js
TypeScript
2
star
44

modtestx

Go
1
star
45

dds-tools

Some old AS/400 tool that was part of the tn5250 project
C
1
star
46

strawtool

Go
1
star
47

modtest2

Go
1
star
48

js.UUID

UUID library for JS.
TypeScript
1
star
49

goutils

Miscellaneous Go utility packages.
Go
1
star
50

x5250

Old x5250 emulator patched to work on modern systems
C
1
star
51

asdbget

Some old AS/400 tool that was part of the tn5250 project
C
1
star
52

gnome-5250

Some old AS/400 tool that was part of the tn5250 project
C
1
star
53

js.SQLAPI-Pg

PostgreSQL database driver for SQLAPI
TypeScript
1
star
54

dexlogconfig

Personal policy and configuration package for xlog.
Go
1
star
55

draft-landau-websec-key-pinning-really

๐Ÿ“œ No, really
Makefile
1
star
56

dedoc

Write technical documents in Scheme
Scheme
1
star
57

xlog

๐Ÿ“„ Logging library for Go
Go
1
star
58

coincheck

IRC Bitcoin ticker written in Go.
Go
1
star
59

ctmon

๐Ÿ”
Go
1
star
60

tftpsrv

๐Ÿ“ Go TFTP server library
Go
1
star
61

ncbtcjsontypes

Namecoin RPC types for btcjson
Go
1
star
62

goproj

Utilities for managing Go projects
Shell
1
star
63

js.Net

Go-style networking library for Node.js
TypeScript
1
star
64

js.Math

Math libraries for JS.
TypeScript
1
star
65

nccald

Namecoin calendar notification daemon (ICS, CalDAV)
Go
1
star
66

hlandau.github.io

HTML
1
star
67

nczilla

๐Ÿšง Mozilla extension under development.
JavaScript
1
star
68

sx

S-expression parser for Go
Go
1
star
69

nctestsuite

Namecoin domain name test suite
Go
1
star
70

js.SQLAPI

Generic SQL driver abstraction layer for Node.js.
TypeScript
1
star