本文整理匯總了Golang中github.com/keep94/vsafe.User.ChangePassword方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.ChangePassword方法的具體用法?Golang User.ChangePassword怎麽用?Golang User.ChangePassword使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/keep94/vsafe.User
的用法示例。
在下文中一共展示了User.ChangePassword方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestChangePassword
func TestChangePassword(t *testing.T) {
user := vsafe.User{Id: 1}
var err error
if err = user.Init("keep94", "somepassword"); err != nil {
t.Fatalf("Error creating user: %v", err)
}
if err = user.ChangePassword("somepassword", "another"); err != nil {
t.Fatalf("Verify password failed: %v", err)
}
if _, err = user.VerifyPassword("another"); err != nil {
t.Error("Expected password to change")
}
if err = user.ChangePassword("somepassword", "be"); err != vsafe.ErrWrongPassword {
t.Errorf("Expected ErrWrongPassword, got %v", err)
}
}
示例2: ChangePassword
// ChangePassword changes the password of a user in persistent storage.
// t, the transaction, must be non nil.
func ChangePassword(
store SafeUpdateUserRunner,
t db.Transaction,
id int64,
oldPass, newPass string) (*vsafe.User, error) {
if t == nil {
panic("Transaction must be non-nil")
}
var user vsafe.User
err := store.UserById(t, id, &user)
if err != nil {
return nil, err
}
if err = user.ChangePassword(oldPass, newPass); err != nil {
return nil, err
}
if err = store.UpdateUser(t, &user); err != nil {
return nil, err
}
return &user, nil
}