* encrypted userid
* added totp_verified column in user table
* started test for totp
This commit is contained in:
lemonScaletech
2023-09-06 18:49:54 +05:30
parent bbb1cf6301
commit a3fa0eb6cd
13 changed files with 157 additions and 289 deletions

View File

@@ -3,8 +3,6 @@ package sql
import (
"bytes"
"context"
"crypto/rand"
"crypto/rsa"
"fmt"
log "github.com/sirupsen/logrus"
"image/png"
@@ -60,18 +58,14 @@ func (p *provider) ValidatePasscode(ctx context.Context, passcode string, id str
if err != nil {
return false, fmt.Errorf("error while getting user details")
}
// validate passcode inputted by user
status := totp.Validate(passcode, *user.TotpSecret)
if !user.TotpVerified {
if status {
user.TotpVerified = true
p.UpdateUser(ctx, user)
return status, nil
}
return status, nil
}
return status, nil
}
func (p *provider) GenerateKeysTOTP() (*rsa.PublicKey, error) {
privateKey, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {
return nil, err
}
publicKey := privateKey.PublicKey
return &publicKey, nil
}