pwdhash

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 10 Imported by: 0

README ยถ

pwdhash ๐Ÿ”

pwdhash is a lightweight, easy-to-use library for secure password hashing and validation in Go. It leverages industry-standard algorithms to ensure your application stays safe without unnecessary complexity.

Features ๐Ÿš€

  • ๐Ÿ”’ Secure hashing with Argon2 (default) or Bcrypt.
  • ๐Ÿ”‘ Easy validation of hashed passwords.
  • โšก Configurable parameters for performance tuning.
  • โœ… Designed for simplicity and readability.

Installation ๐Ÿ“ฆ

Install the library using go get:

go get github.com/sppps/pwdhash

Quick Start ๐ŸŒŸ

1. Hashing a password
package main

import (
    "fmt"
    "github.com/sppps/pwdhash"
)

func main() {
    password := "MySecureP@ssw0rd"

    // Hash the password
    hash, err := pwdhash.Hash(password)
    if err != nil {
        panic(err)
    }

    fmt.Println("Hashed password:", hash)
}
2. Validating a password
package main

import (
    "fmt"
    "github.com/sppps/pwdhash"
)

func main() {
    hash := "$argon2id$v=19$m=65536,t=3,p=2$..." // Example hash
    password := "MySecureP@ssw0rd"

    // Validate the password
    match := hash.Validate(password, hash)
    if match == nil {
        fmt.Println("Password is valid!")
    } else {
        fmt.Println("Invalid password!")
    }
}

Configuration โš™๏ธ

You can customize the hashing algorithm and parameters:

gopassword.SetConfig(gopassword.Config{
    Algorithm: gopassword.Argon2id, // or gopassword.Bcrypt
    Memory:    65536,              // Argon2-specific
    Time:      3,
    Threads:   2,
})

Why Use pwdhash? ๐Ÿค”

  • Security: Follows best practices for password hashing.
  • Simplicity: Easy-to-read API for developers of all levels.
  • Flexibility: Configurable for various application needs.

Roadmap ๐Ÿ›ฃ๏ธ

  • Add support for Scrypt.
  • Benchmark performance against other libraries.
  • Implement automatic upgrades for old password hashes.

Contributing ๐Ÿค

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-name).
  3. Commit your changes (git commit -m "Add feature").
  4. Push to the branch (git push origin feature-name).
  5. Create a pull request.

License ๐Ÿ“„

his project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments ๐Ÿ™

Inspired by the simplicity of bcrypt and argon2. Thanks to the Go community for their amazing tools and libraries.

Contact โœ‰๏ธ

Feel free to reach out with feedback, questions, or suggestions!

GitHub Email

Documentation ยถ

Index ยถ

Constants ยถ

This section is empty.

Variables ยถ

View Source
var DefaultConfig = Config{
	Algorithm: Argon2id,
	Memory:    64 * 1024,
	Time:      3,
	Threads:   4,
	Cost:      bcrypt.DefaultCost,
}

provides the default configuration for hashing

View Source
var ParanoidConfig = Config{
	Algorithm: Argon2id,
	Memory:    192 * 1024,
	Time:      12,
	Threads:   8,
	Cost:      bcrypt.MaxCost,
}

provides the paranoid configuration for hashing.

Functions ยถ

func Hash ยถ

func Hash(password string) (string, error)

generates a secure hash for the given password

func SetConfig ยถ

func SetConfig(cfg Config)

sets the global configuration for password hashing

func Validate ยถ

func Validate(password, hash string) error

checks if the provided password matches the hashed password

Types ยถ

type Algorithm ยถ

type Algorithm int

defines the supported hashing algorithms.

const (
	Argon2id Algorithm = iota
	Bcrypt
)

type Config ยถ

type Config struct {
	Algorithm Algorithm // hashing algorithm (Argon2, Bcrypt)
	Memory    uint32    // Argon2 memory
	Time      uint32    // Argon2 timer
	Threads   uint8     // Argon2 parallelism
	Cost      int       // Bcrypt cost
	RandSrc   io.Reader // random number generator
}

stores configuration parameters for password hashing.

func GetConfig ยถ

func GetConfig() Config

returns the current hashing configuration

func (Config) String ยถ

func (c Config) String() (s string)

Directories ยถ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher ๐Ÿ‡ป๐Ÿ‡ณ