security

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) (bool, error)

CheckPasswordHash compares a plain text password with a bcrypt hash. It returns true if the password matches the hash, false otherwise.

Parameters:

  • password: The plain text password to verify
  • hash: The bcrypt hash to compare against

Returns:

  • bool: true if password matches, false otherwise
  • error: nil if comparison succeeded (even if password doesn't match), error only for unexpected failures (e.g., corrupted hash)

Example:

valid, err := security.CheckPasswordHash("myPassword123", hashedPassword)
if err != nil {
    log.Fatal(err)
}
if !valid {
    fmt.Println("Invalid password")
}

func HashPassword

func HashPassword(password string) string

HashPassword hashes a password using bcrypt with the default cost factor. It returns the bcrypt hash as a string, or an empty string if hashing fails.

Parameters:

  • password: The plain text password to hash

Returns:

  • string: The bcrypt hash (60 characters), or empty string on error

Example:

hash := security.HashPassword("myPassword123")
if hash == "" {
    log.Fatal("Failed to hash password")
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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