secure

package
v0.0.2-beta.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package secure provides security-related utilities including password hashing, string censoring, and random string generation for tokens and passwords. It uses industry-standard algorithms like bcrypt for secure password storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CensorString

func CensorString(src string, outLength int) string

CensorString masks a string by replacing middle characters with asterisks while preserving the first and last characters for recognition. The output length is controlled by outLength parameter. If the source string has only one character, it's repeated at both ends with asterisks in between.

func CryptPassword

func CryptPassword(pwd string) string

CryptPassword hashes a plain text password using bcrypt with default cost. It returns the hashed password string, or the original password if hashing fails. The bcrypt algorithm includes salt generation and is resistant to rainbow table attacks.

func IsPasswordMatch

func IsPasswordMatch(pwd, cyPwd string) bool

IsPasswordMatch verifies if a plain text password matches the provided bcrypt hash. It returns true if the password matches the hash, false otherwise. This function is safe against timing attacks due to bcrypt's constant-time comparison.

func RandString

func RandString(length int) string

RandString generates a random string of the specified length using alphanumeric characters. It uses cryptographically secure random number generation for creating unpredictable strings suitable for tokens, passwords, or other security-sensitive applications.

Types

This section is empty.

Jump to

Keyboard shortcuts

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