-
Notifications
You must be signed in to change notification settings - Fork 28
/
pin.go
42 lines (32 loc) · 854 Bytes
/
pin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
Copyright Avast Software. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package otp
import (
"fmt"
"math/rand"
"strings"
)
const (
maxNumber = 10
)
// PinGenerator implements logic for generating and verifying otp pin codes.
type PinGenerator struct {
}
// NewPinGenerator creates a new instance of PinGenerator.
func NewPinGenerator() *PinGenerator {
return &PinGenerator{}
}
// Generate generates a new pin based on challenge
func (p *PinGenerator) Generate(_ string) string {
var finalPin strings.Builder
for i := 0; i < 6; i++ {
finalPin.WriteString(fmt.Sprint(rand.Int31n(maxNumber))) //nolint:gosec
}
return finalPin.String()
}
// Validate validates pin
func (p *PinGenerator) Validate(challenge string, userInput string) bool { // in future there will be more implementations
return challenge == userInput
}