bcryptio

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package bcryptio provides minimal wrappers around the bcrypt package to allow for command-line operations such as comparing passwords, checking costs, generating hashes, and generating random passwords with their hashes.

Index

Constants

View Source
const (
	// DefaultLength is the default length of the a password.
	DefaultLength = 20
)

Variables

This section is empty.

Functions

func Compare

func Compare(inr io.Reader, outw io.Writer) error

Compare reads a previously hashed password from the input reader and a plain text password, then compares them using bcrypt.

If the plain text password matches the hashed password, it prints a success message; otherwise, it returns an error.

func Cost

func Cost(inr io.Reader, outw io.Writer) error

Cost reads a previously hashed password from the input reader and prints the cost used to create that hash.

If the hash is invalid, an error is returned.

func Generate

func Generate(outw io.Writer, symbols bool, length, cost int) error

Generate creates a random password of the specified length, hashes it using bcrypt with the specified cost, and writes both the plaintext password and the hashed password to the output writer.

If symbols is true, the password will include symbols; otherwise, it will only include alphanumeric characters.

If the length is less than DefaultLength, it will be set to DefaultLength.

If the length exceeds maxLength, it will be set to maxLength.

The cost parameter determines the computational cost of hashing the password.

If an error occurs during password generation or hashing, it will be returned.

func Hash

func Hash(inr io.Reader, out io.Writer, cost int) error

Hash reads a password from the input reader, confirms it by reading it again, and then hashes it using bcrypt with the specified cost. The hashed password is written to the output writer.

If the passwords do not match, an error is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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