Libxcrypt compatible go library.
Go to file
2024-09-07 18:53:27 -05:00
.gitignore First commit 2024-09-07 18:53:27 -05:00
go.mod First commit 2024-09-07 18:53:27 -05:00
go.sum First commit 2024-09-07 18:53:27 -05:00
gost_yes_crypt.go First commit 2024-09-07 18:53:27 -05:00
LICENSE.txt First commit 2024-09-07 18:53:27 -05:00
md5_crypt.go First commit 2024-09-07 18:53:27 -05:00
nt_hash.go First commit 2024-09-07 18:53:27 -05:00
passwd_test.go First commit 2024-09-07 18:53:27 -05:00
passwd.go First commit 2024-09-07 18:53:27 -05:00
pbkdf1_sha1_crypt.go First commit 2024-09-07 18:53:27 -05:00
README.md First commit 2024-09-07 18:53:27 -05:00
s_crypt.go First commit 2024-09-07 18:53:27 -05:00
sha256_crypt.go First commit 2024-09-07 18:53:27 -05:00
sha512_crypt.go First commit 2024-09-07 18:53:27 -05:00
sun_md5.go First commit 2024-09-07 18:53:27 -05:00
utils.go First commit 2024-09-07 18:53:27 -05:00
yes_crypt.go First commit 2024-09-07 18:53:27 -05:00

go-passwd

This is a libxcrypt compatible password hashing library for the Go language. The passwords generated with this library is fully compatible with libxcrypt which can be used to generate or test passwords in use by software such as MySQL or the Linux shadow system.

Install

go get github.com/GRMrGecko/go-passwd

Example

package main

import (
	"github.com/GRMrGecko/go-passwd"
	"log"
)

func main() {
	result, err := passwd.CheckPassword([]byte("$y$j9T$Q3N1jZa3Cp.yNINNDt5dDgYkHU7k$9o7WJJB5F.tTEhZdz6T6LMWY/0C3JkhvmcNyUPvUBlC"), []byte("Test"))
	if err != nil {
		log.Fatalln(err)
	}

	if result {
		log.Println("Password confirmed, saving new password.")

		pw := passwd.NewSHA512CryptPasswd()
		hash, err := pw.HashPassword([]byte("New Password!!!"))
		if err != nil {
			log.Fatalln(err)
		}
		log.Println("The new password hash to save is:", string(hash))
	}
}

Example output:

$ ./test
2024/09/07 18:42:35 Password confirmed, saving new password.
2024/09/07 18:42:35 The new password hash to save is: $6$4Eu/l5e.otcRj0rJ$YAlwxJD9pZY9.Z2TjseCbkXiUIrFU2AXh9DPEm5Z1SagxP..xaQCsz7jAgfW4nmUbLh.o23pEZGvvxPCLltf11

Docs

https://pkg.go.dev/github.com/GRMrGecko/go-passwd

Known issues

  • It is possible to generate password hashes that are incompatible with libxcrypt by setting a large round count. This may be mitigated in the future by adding an option to disable compatibility and otherwise require compatible parameters to be set.
  • The bcrypt hashing algorithms are not implemented yet, it may be implemented in the near futre.