Files
komari/utils/random.go
T
Akizon77 9f7758f1da Refactor database structure and session management
- Removed legacy session management code from `session.go` and `sqlite3.go`.
- Introduced new `accounts` package for user and session management.
- Implemented GORM for database interactions, replacing raw SQL queries.
- Created models for `User`, `Session`, `Client`, `History`, and other entities.
- Added functions for creating, retrieving, and deleting sessions.
- Implemented automatic cleanup of old history records.
- Updated `main.go` to initialize the database and create a default admin account.
- Enhanced error handling and logging throughout the database operations.
2025-04-15 21:14:55 +08:00

25 lines
438 B
Go

package utils
import (
"encoding/base64"
"math/rand"
"time"
)
func GenerateRandomString(length int) string {
b := make([]byte, length)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
_, err := r.Read(b)
if err != nil {
return ""
}
return base64.URLEncoding.EncodeToString(b)[:length]
}
func GeneratePassword() string {
return GenerateRandomString(12)
}
func GenerateToken() string {
return GenerateRandomString(16)
}