
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
github.com/YashSaini99/graphical-password-authentication
Graphical Password Authentication is a Go package that secures user login with image-based password patterns. It converts selected image indices into a string, hashes it with bcrypt, and stores it in MongoDB. It also features brute-force protection, email alerts, and secure password resets.
To install the package, use:
go get github.com/YashSaini99/gpass
Create a .env
file in the root of your project with the following keys:
# Database Configuration
DB_URI=mongodb://localhost:27017/graphicalpasswordauth
# SMTP Configuration (example using Mailtrap for testing)
SMTP_USER=your_mailtrap_username@mailtrap.io
SMTP_PASS=your_mailtrap_password
SMTP_HOST=smtp.mailtrap.io
SMTP_PORT=2525
import (
"github.com/YashSaini99/gpass"
"time"
)
func main() {
// Load environment variables
gpass.LoadEnv()
// Connect to the database
err := gpass.Connect("your_mongodb_connection_string")
if err != nil {
// Handle error
}
defer gpass.Disconnect()
// Validate an email
if !gpass.IsValidEmail("user@example.com") {
// Handle invalid email
}
// Register a new user
err = gpass.RegisterUser("username", "user@example.com", []int{1, 3, 5, 7})
if err != nil {
// Handle error (e.g., duplicate username/email)
}
// Authenticate the user
ok, err := gpass.AuthenticateUser("username", []int{1, 3, 5, 7})
if err != nil {
// Handle error
}
if ok {
// Successful login
}
}
For added security, use the advanced functions that protect against brute-force attacks and support password resets.
// Create a SecureAuthManager instance
secManager := gpass.NewSecureAuthManager(3, 10*time.Minute, 15*time.Minute)
// Authenticate with protection (this will block the account on repeated failed attempts and send alert emails)
ok, err := secManager.AuthenticateWithProtection("username", []int{1, 3, 5, 7}, "user@example.com")
if err != nil {
// Handle authentication error (e.g., account blocked)
}
if ok {
// Successful login
}
// Initiate a password reset (generates a secure token and sends a reset email)
token, err := secManager.InitiatePasswordReset("username", "user@example.com")
if err != nil {
// Handle password reset error
}
// Use the token for resetting the password, typically via a dedicated reset endpoint.
// Validate an email
if gpass.IsValidEmail("user@example.com") {
fmt.Println("Email is valid")
} else {
fmt.Println("Email is invalid")
}
// Send an email
err := gpass.SendEmail("user@example.com", "Subject", "Email body")
if err != nil {
// Handle email sending error
}
LoadEnv() error
Loads environment variables from a .env
file.
Connect(uri string) error
Connects to MongoDB using the provided URI.
Disconnect() error
Disconnects from MongoDB.
RegisterUser(username, email string, graphicalPassword []int) error
Registers a new user.
AuthenticateUser(username string, graphicalPassword []int) (bool, error)
Authenticates a user with their graphical password.
IsValidEmail(email string) bool
Validates an email address.
SendEmail(to, subject, body string) error
Sends an email using the SMTP settings in your .env
file.
NewSecureAuthManager(threshold int, blockDuration, tokenDuration time.Duration) *SecureAuthManager
Creates a new instance of SecureAuthManager.
(m *SecureAuthManager) AuthenticateWithProtection(username string, graphicalPassword []int, userEmail string) (bool, error)
Authenticates a user with brute-force protection.
(m *SecureAuthManager) InitiatePasswordReset(username, userEmail string) (string, error)
Initiates a password reset, sending a reset email with a secure token.
(m *SecureAuthManager) ValidateResetToken(username, token string) bool
Validates a password reset token.
To run the tests for this package:
go test ./tests
This will execute unit tests for core functionalities such as hashing, email validation, and more.
Contributions are welcome! If you have ideas for enhancements, bug fixes, or additional features, please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.