2023-10-07 13:48:40 +00:00
|
|
|
package scsusers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"time"
|
2023-10-07 13:55:21 +00:00
|
|
|
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
2023-10-07 13:48:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func RecoverByEmail(email string) {
|
|
|
|
u, ok := Get(email)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
recoverycode := generatePassword(16)
|
|
|
|
u.Delete("recoverycode")
|
|
|
|
u.Delete("recoverytime")
|
|
|
|
|
2023-10-07 13:55:21 +00:00
|
|
|
crypt, err := bcrypt.GenerateFromPassword(recoverycode, 10)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("pass generation failed")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
u.Set("recoverycode", string(crypt))
|
2023-10-07 13:48:40 +00:00
|
|
|
u.Set("recoverytime", fmt.Sprintf("%d", time.Now().Add(time.Minute*60).Unix()))
|
|
|
|
|
|
|
|
SendRecoveryEmail(email, email, string(recoverycode))
|
|
|
|
}
|