-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpassword.go
42 lines (38 loc) · 945 Bytes
/
password.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
package vault
import (
"github.com/keys-pub/keys"
"github.com/keys-pub/vault/auth"
)
// SetupPassword setup vault with a password.
func (v *Vault) SetupPassword(password string) (*[32]byte, error) {
mk := keys.Rand32()
if _, err := v.auth.RegisterPassword(password, mk); err != nil {
return nil, err
}
if err := v.Setup(mk); err != nil {
return nil, err
}
return mk, nil
}
// RegisterPassword adds a password.
func (v *Vault) RegisterPassword(mk *[32]byte, password string) (*auth.Auth, error) {
if v.db == nil {
return nil, ErrLocked
}
reg, err := v.auth.RegisterPassword(password, mk)
if err != nil {
return nil, err
}
return reg, nil
}
// UnlockWithPassword opens vault with a password.
func (v *Vault) UnlockWithPassword(password string) (*[32]byte, error) {
_, mk, err := v.auth.Password(password)
if err != nil {
return nil, err
}
if err := v.Unlock(mk); err != nil {
return nil, err
}
return mk, nil
}