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 ¶
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 ¶
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 ¶
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 ¶
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.