package
0.0.0-20240731084147-8c2c48fecfe2
Repository: https://github.com/jimsyyap/golang_recipe.git
Documentation: pkg.go.dev
# README
Imagine you want to store your secret passwords safely on your computer. This Golang code is like a tool to securely store and check those passwords.
The Thought Process:
- Problem: We can't store passwords directly because someone might steal them.
- Solution: Hashing: The code uses a special process called hashing to turn your password into a scrambled mess (hash) that can't be easily turned back into the original password. It's like turning your secret message into a weird code that only you and the tool understand.
- Security: It's important to make this hash strong, so it takes a long time to crack. The code uses a setting called "cost" to control how strong the hash is.
- Checking Passwords: When you want to log in, you enter your password. The code turns it into a hash again and compares it to the stored hash (like checking your weird code against the original one). If they match, then your password is correct.
Step-by-Step Breakdown:
- There's a pre-generated, scrambled password stored in the code (
storedHash
). Imagine this is the secure version of your real password stored on the computer. - When you run the program, it asks you to type your password.
- The code turns your password into a scrambled hash using a strong setting (
bcrypt.DefaultCost
). - It compares the newly created hash to the stored one (
storedHash
). - If the hashes match, it means your password is correct (like your weird code matching the stored one).
Decisions Made:
- The code uses a secure hashing algorithm called bcrypt.
- It sets the cost to a default strong level for added security.
- It logs messages to tell you if the password is correct or not.
Remember: This is a simplified explanation. In real use, passwords should be stored in a secure database and not directly in the code.