https://github.com/marcelofabianov/doberman
Go PKG para gerenciamento de senhas, oferecendo geração e validação configuráveis e hashing moderno com Argon2id.
https://github.com/marcelofabianov/doberman
argo2 package password security type-safe validation
Last synced: 6 months ago
JSON representation
Go PKG para gerenciamento de senhas, oferecendo geração e validação configuráveis e hashing moderno com Argon2id.
- Host: GitHub
- URL: https://github.com/marcelofabianov/doberman
- Owner: marcelofabianov
- License: mit
- Created: 2025-07-21T14:47:57.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-10-06T22:44:00.000Z (10 months ago)
- Last Synced: 2025-10-07T00:21:14.708Z (10 months ago)
- Topics: argo2, package, password, security, type-safe, validation
- Language: Go
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Doberman
Doberman is a Go package for secure password generation, validation, and handling. It provides a customizable password validator, supports JSON serialization/deserialization, and integrates with SQL databases using the `database/sql` package.
## Features
- Generate random passwords with customizable requirements (length, character types).
- Validate passwords against configurable rules (minimum length, required numbers, uppercase, lowercase, symbols).
- Securely handle passwords with JSON marshaling/unmarshaling.
- Support for SQL database integration with `Scan` and `Value` methods.
- Error handling using the `github.com/marcelofabianov/fault` package.
## Installation
To use Doberman in your Go project, run:
```bash
go get github.com/marcelofabianov/doberman
```
Ensure you have the `fault` package installed:
```bash
go get github.com/marcelofabianov/fault
```
## Usage
### Creating a Password Validator
Create a `PasswordValidator` with default or custom configuration:
```go
package main
import (
"fmt"
"github.com/marcelofabianov/doberman"
)
func main() {
// Use default configuration (min length: 10, requires number, uppercase, lowercase, symbol)
validator := doberman.NewPasswordValidator(nil)
// Custom configuration
customConfig := &doberman.PasswordConfig{
MinLength: 12,
RequireNumber: true,
RequireUpper: true,
RequireLower: true,
RequireSymbol: false,
}
customValidator := doberman.NewPasswordValidator(customConfig)
}
```
### Generating a Password
Generate a random password that meets the validator's requirements:
```go
password, err := validator.Generate()
if err != nil {
fmt.Printf("Error generating password: %v\n", err)
return
}
fmt.Printf("Generated password: %s\n", password.String())
```
### Validating a Password
Validate a password against the configured rules:
```go
err := validator.Validate("MySecureP@ss1")
if err != nil {
fmt.Printf("Validation failed: %v\n", err)
} else {
fmt.Println("Password is valid")
}
```
### Creating a Password
Create a `Password` type with validation:
```go
password, err := doberman.NewPassword("MySecureP@ss1")
if err != nil {
fmt.Printf("Invalid password: %v\n", err)
return
}
fmt.Printf("Created password: %s\n", password.String())
```
For panic-on-error behavior:
```go
password := doberman.MustNewPassword("MySecureP@ss1")
fmt.Printf("Created password: %s\n", password.String())
```
### Database Integration
Use the `Password` type with SQL databases:
```go
import (
"database/sql"
"fmt"
"github.com/marcelofabianov/doberman"
_ "github.com/mattn/go-sqlite3"
)
func main() {
db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
fmt.Printf("Error opening database: %v\n", err)
return
}
defer db.Close()
// Create table
_, err = db.Exec("CREATE TABLE users (id INTEGER PRIMARY KEY, password TEXT)")
if err != nil {
fmt.Printf("Error creating table: %v\n", err)
return
}
// Insert password
password, _ := doberman.NewPassword("DatabaseP@ss1")
_, err = db.Exec("INSERT INTO users (password) VALUES (?)", password)
if err != nil {
fmt.Printf("Error inserting: %v\n", err)
return
}
// Query password
var scannedPassword doberman.Password
err = db.QueryRow("SELECT password FROM users WHERE id = 1").Scan(&scannedPassword)
if err != nil {
fmt.Printf("Error querying: %v\n", err)
return
}
fmt.Printf("Scanned password: %s\n", scannedPassword.String())
}
```
## Error Handling
Doberman uses the `fault` package for structured error handling. Errors include a message, code, context, and wrapped errors:
```go
password, err := doberman.NewPassword("invalid")
if err != nil {
fmt.Printf("Error: %s, Code: %s, Context: %v\n", err.Message, err.Code, err.Context)
}
```
## Testing
Run the tests to verify functionality:
```bash
go test -v ./...
```
## Contributing
Contributions are welcome! Please submit issues or pull requests to the [GitHub repository](https://github.com/marcelofabianov/doberman).
## License
This project is licensed under the MIT License.