|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PasswordPolicy 密码策略
|
|
|
|
type PasswordPolicy struct {
|
|
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
|
|
Level int `gorm:"not null;default:1" json:"level"` // 密码策略等级 0-5
|
|
|
|
MinRequiredLevel int `gorm:"not null;default:1" json:"min_required_level"` // 新增:系统要求的最低密码强度等级
|
|
|
|
MinLength int `gorm:"not null;default:6" json:"min_length"` // 最小长度
|
|
|
|
RequireUppercase bool `gorm:"not null;default:false" json:"require_uppercase"` // 要求大写字母
|
|
|
|
RequireLowercase bool `gorm:"not null;default:false" json:"require_lowercase"` // 要求小写字母
|
|
|
|
RequireNumbers bool `gorm:"not null;default:false" json:"require_numbers"` // 要求数字
|
|
|
|
RequireSpecial bool `gorm:"not null;default:false" json:"require_special"` // 要求特殊字符
|
|
|
|
MinCharTypes int `gorm:"not null;default:1" json:"min_char_types"` // 最少字符类型数
|
|
|
|
ExpirationDays int `gorm:"not null;default:30" json:"expiration_days"` // 密码失效天数
|
|
|
|
PreventReuse int `gorm:"not null;default:3" json:"prevent_reuse"` // 防止重复使用前N次密码
|
|
|
|
IsActive bool `gorm:"not null;default:true" json:"is_active"` // 是否启用
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// PasswordHistory 密码历史记录
|
|
|
|
type PasswordHistory struct {
|
|
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
|
|
UserID uint `gorm:"not null;index" json:"user_id"` // 用户ID
|
|
|
|
Password string `gorm:"not null;size:255" json:"password"` // 加密后的密码(bcrypt哈希)
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// PasswordReset 密码重置记录
|
|
|
|
type PasswordReset struct {
|
|
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
|
|
UserID uint `gorm:"not null;index" json:"user_id"` // 用户ID
|
|
|
|
ResetBy uint `gorm:"not null" json:"reset_by"` // 重置操作人ID
|
|
|
|
ResetAt time.Time `gorm:"not null" json:"reset_at"` // 重置时间
|
|
|
|
IsUsed bool `gorm:"not null;default:false" json:"is_used"` // 是否已使用
|
|
|
|
UsedAt *time.Time `json:"used_at"` // 使用时间
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// PasswordChangeRequest 密码修改请求
|
|
|
|
type PasswordChangeRequest struct {
|
|
|
|
UserID uint `json:"user_id"`
|
|
|
|
CurrentPassword string `json:"current_password"`
|
|
|
|
NewPassword string `json:"new_password"`
|
|
|
|
ConfirmPassword string `json:"confirm_password"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// PasswordValidationResult 密码验证结果
|
|
|
|
type PasswordValidationResult struct {
|
|
|
|
IsValid bool `json:"is_valid"`
|
|
|
|
Errors []string `json:"errors"`
|
|
|
|
Strength int `json:"strength"` // 密码强度 0-100
|
|
|
|
Level int `json:"level"` // 符合的密码等级
|
|
|
|
}
|