Exemplo n.º 1
0
// ChangePassword changes the password of this user.
func (u *User) ChangePassword(oldPass, newPass string) error {
	var key []byte
	var err error
	if key, err = u.verifyPassword(oldPass); err != nil {
		return err
	}
	u.Key, err = aes.EncryptB(key, kdf.KDF([]byte(newPass), kdf.DefaultSalt, kdf.DefaultReps))
	return err
}
Exemplo n.º 2
0
// InitWithKey initializes this user instance with a user name and password
// so that the user uses key as its key.
func (u *User) InitWithKey(name, password string, key *Key) (err error) {
	u.Owner = key.Id
	u.Name = name
	if u.Key, err = aes.EncryptB(
		key.Value,
		kdf.KDF(
			[]byte(password),
			kdf.DefaultSalt,
			kdf.DefaultReps)); err != nil {
		return
	}
	u.Checksum = base64.StdEncoding.EncodeToString(
		kdf.NewHMAC(key.Value, kdf.DefaultReps))
	return
}