bcryptencryptor

package module
v0.0.0-...-a00e3b3 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2023 License: MIT Imports: 1 Imported by: 0

README

go-bcrypt-encryptor

go-bcrypt-encryptor is a Go package for password encryption and comparison using the bcrypt algorithm.

Installation

Get and install the go-bcrypt-encryptor package from GitHub using the following command:

go get github.com/lichuan6/go-bcrypt-encryptor

Usage

Import the go-bcrypt-encryptor package:

import "github.com/lichuan6/go-bcrypt-encryptor"

Create a new BcryptEncryptor instance:

encryptor := bcryptencryptor.NewBcryptEncryptor(bcrypt.DefaultCost)
Encrypting Passwords
password := "myPassword"
encryptedPassword, err := encryptor.Encrypt(password)
if err != nil {
    // Handle error
}
Comparing Passwords
password := "myPassword"
err := encryptor.Compare(encryptedPassword, password)
if err != nil {
    // Passwords do not match
}
Hash and Password Comparison
password := "myPassword"
err := encryptor.CompareHashAndPassword(encryptedPassword, password)
if err != nil {
    // Passwords do not match
}

Testing

Run the following command to execute the tests for the go-bcrypt-encryptor package:

go test github.com/lichuan6/go-bcrypt-encryptor

Contribution

If you find any bugs or have suggestions for improvement, please create an issue on GitHub or submit a pull request. We welcome and appreciate your contributions!

License

The go-bcrypt-encryptor package is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BcryptEncryptor

type BcryptEncryptor struct {
	// contains filtered or unexported fields
}

func NewBcryptEncryptor

func NewBcryptEncryptor(cost int) *BcryptEncryptor

func (*BcryptEncryptor) Compare

func (b *BcryptEncryptor) Compare(encryptedPassword, password string) error

func (*BcryptEncryptor) CompareHashAndPassword

func (b *BcryptEncryptor) CompareHashAndPassword(hashedPassword, password string) error

func (*BcryptEncryptor) Encrypt

func (b *BcryptEncryptor) Encrypt(password string) (string, error)

type PasswordEncryptor

type PasswordEncryptor interface {
	Encrypt(password string) (string, error)
	Compare(encryptedPassword, password string) error
	CompareHashAndPassword(hashedPassword, password string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL