update/hash-pass-history
This commit is contained in:
1 parent
516eb8c9e0
commit
c56dc732bd
2 files changed
+27
-6
No files matched your search
+15
-5
@@ -45,16 +45,26 @@ type Student struct {
|
||||
Photo string `json:"photo"`
|
||||
} `json:"schooldata"`
|
||||
AccountData struct {
|
||||
SchoolEmail string `json:"schoolemail"`
|
||||
Password string `json:"-" validate:"min=10,max=32"`
|
||||
AccountDisabled bool `bson:"accountdisabled"`
|
||||
TempPassword bool `json:"temppassword"`
|
||||
Attempts int `json:"attempts"` // login attempts max 5
|
||||
SchoolEmail string `json:"schoolemail"`
|
||||
Password string `json:"-" validate:"min=10,max=32"`
|
||||
AccountDisabled bool `bson:"accountdisabled"`
|
||||
TempPassword bool `json:"temppassword"`
|
||||
Attempts int `json:"attempts"` // login attempts max 5
|
||||
HashHistory []string `json:"-"` // List of old hashed passwords (not including auto generated passwords)
|
||||
} `json:"accountdata"`
|
||||
Created_at time.Time `json:"created_at"`
|
||||
Updated_at time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (s *Student) UsedPassword(password string) bool {
|
||||
for _, oldHash := range s.AccountData.HashHistory {
|
||||
if oldHash == s.HashPassword(password) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Student) HashPassword(password string) string {
|
||||
hash, _ := bcrypt.GenerateFromPassword([]byte(password), 14)
|
||||
return string(hash)
|
||||
|
||||
Reference in new issue
Block a user