Skip to content

Commit 4844907

Browse files
committed
Rename Credential.Reset*() methods to Credential.ChangePassword*() to reflect the actual functionality
Addresses part 2 of #7
1 parent 74ed5a1 commit 4844907

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

credential.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,23 @@ func (c *Credential) MatchesPasswordWithConfigAndIP(config Config, password stri
9797
return
9898
}
9999

100-
// Reset resets the password for the given Credential and updates the Credential to use the recommended safe key derivation function and parameters
101-
func (c *Credential) Reset(oldPassword, newPassword string) error {
102-
return c.ResetWithConfig(DefaultConfig, oldPassword, newPassword)
100+
// ChangePassword changes the password for the given Credential and updates the Credential to use the recommended safe key derivation function and parameters
101+
func (c *Credential) ChangePassword(oldPassword, newPassword string) error {
102+
return c.ChangePasswordWithConfig(DefaultConfig, oldPassword, newPassword)
103103
}
104104

105-
// ResetWithIP resets the password for the given Credential and updates the Credential to use the recommended safe key derivation function and parameters
106-
func (c *Credential) ResetWithIP(oldPassword, newPassword string, ip net.IP) error {
107-
return c.ResetWithConfigAndIP(DefaultConfig, oldPassword, newPassword, ip)
105+
// ChangePasswordWithIP changes the password for the given Credential and updates the Credential to use the recommended safe key derivation function and parameters
106+
func (c *Credential) ChangePasswordWithIP(oldPassword, newPassword string, ip net.IP) error {
107+
return c.ChangePasswordWithConfigAndIP(DefaultConfig, oldPassword, newPassword, ip)
108108
}
109109

110-
// ResetWithConfig resets the password for the given Credential and updates the Credential to meet the Config parameters if necessary
111-
func (c *Credential) ResetWithConfig(config Config, oldPassword, newPassword string) error {
112-
return c.ResetWithConfigAndIP(config, oldPassword, newPassword, emptyIP)
110+
// ChangePasswordWithConfig changes the password for the given Credential and updates the Credential to meet the Config parameters if necessary
111+
func (c *Credential) ChangePasswordWithConfig(config Config, oldPassword, newPassword string) error {
112+
return c.ChangePasswordWithConfigAndIP(config, oldPassword, newPassword, emptyIP)
113113
}
114114

115-
// ResetWithConfigAndIP resets the password for the given Credential and updates the Credential to meet the Config parameters if necessary
116-
func (c *Credential) ResetWithConfigAndIP(config Config, oldPassword, newPassword string, ip net.IP) error {
115+
// ChangePasswordWithConfigAndIP changes the password for the given Credential and updates the Credential to meet the Config parameters if necessary
116+
func (c *Credential) ChangePasswordWithConfigAndIP(config Config, oldPassword, newPassword string, ip net.IP) error {
117117
if !c.matchPassword(oldPassword, config.AuditLogger, ip) {
118118
return fmt.Errorf("Old password does not match existing password")
119119
}

credential_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -311,74 +311,74 @@ func TestMatchesPasswordUpdateWorkFactor(t *testing.T) {
311311
}
312312
}
313313

314-
func TestReset(t *testing.T) {
314+
func TestChangePassword(t *testing.T) {
315315
userID := UserID(0)
316316
password := "insecurepassword"
317317
credential, err := NewCredential(userID, password)
318318
if err != nil {
319319
t.Error("Unable to create new Credential")
320320
}
321-
if err := credential.Reset(password, "newInsecurePassword"); err != nil {
321+
if err := credential.ChangePassword(password, "newInsecurePassword"); err != nil {
322322
t.Error("Got error resetting password.", err)
323323
}
324324
}
325325

326-
func TestResetNewPasswordDoesNotMeetPasswordPolicy(t *testing.T) {
326+
func TestChangePasswordNewPasswordDoesNotMeetPasswordPolicy(t *testing.T) {
327327
userID := UserID(0)
328328
password := "insecurepassword"
329329
credential, err := NewCredential(userID, password)
330330
if err != nil {
331331
t.Error("Unable to create new Credential")
332332
}
333-
if err := credential.Reset(password, "tooshort"); err == nil {
333+
if err := credential.ChangePassword(password, "tooshort"); err == nil {
334334
t.Error("Should have gotten error resetting password")
335335
}
336336
}
337337

338-
func TestResetIncorrectOldPassword(t *testing.T) {
338+
func TestChangePasswordIncorrectOldPassword(t *testing.T) {
339339
userID := UserID(0)
340340
password := "insecurepassword"
341341
credential, err := NewCredential(userID, password)
342342
if err != nil {
343343
t.Error("Unable to create new Credential")
344344
}
345-
if err := credential.Reset("wrongPassword", "newInsecurePassword"); err == nil {
345+
if err := credential.ChangePassword("wrongPassword", "newInsecurePassword"); err == nil {
346346
t.Error("Should have gotten error resetting password")
347347
}
348348
}
349349

350-
func TestResetWithIP(t *testing.T) {
350+
func TestChangePasswordWithIP(t *testing.T) {
351351
userID := UserID(0)
352352
password := "insecurepassword"
353353
credential, err := NewCredential(userID, password)
354354
if err != nil {
355355
t.Error("Unable to create new Credential")
356356
}
357-
if err := credential.ResetWithIP(password, "newInsecurePassword", emptyIP); err != nil {
357+
if err := credential.ChangePasswordWithIP(password, "newInsecurePassword", emptyIP); err != nil {
358358
t.Error("Got error resetting password.", err)
359359
}
360360
}
361361

362-
func TestResetWithIPNewPasswordDoesNotMeetPasswordPolicy(t *testing.T) {
362+
func TestChangePasswordWithIPNewPasswordDoesNotMeetPasswordPolicy(t *testing.T) {
363363
userID := UserID(0)
364364
password := "insecurepassword"
365365
credential, err := NewCredential(userID, password)
366366
if err != nil {
367367
t.Error("Unable to create new Credential")
368368
}
369-
if err := credential.ResetWithIP(password, "tooshort", emptyIP); err == nil {
369+
if err := credential.ChangePasswordWithIP(password, "tooshort", emptyIP); err == nil {
370370
t.Error("Should have gotten error resetting password")
371371
}
372372
}
373373

374-
func TestResetWithIPIncorrectOldPassword(t *testing.T) {
374+
func TestChangePasswordWithIPIncorrectOldPassword(t *testing.T) {
375375
userID := UserID(0)
376376
password := "insecurepassword"
377377
credential, err := NewCredential(userID, password)
378378
if err != nil {
379379
t.Error("Unable to create new Credential")
380380
}
381-
if err := credential.ResetWithIP("wrongPassword", "newInsecurePassword", emptyIP); err == nil {
381+
if err := credential.ChangePasswordWithIP("wrongPassword", "newInsecurePassword", emptyIP); err == nil {
382382
t.Error("Should have gotten error resetting password")
383383
}
384384
}

passhash_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func Example() {
101101
// store.Marshal(credential)
102102
}
103103
newPassword := "newinsecurepassword"
104-
if err = credential.Reset(password, newPassword); err != nil {
104+
if err = credential.ChangePassword(password, newPassword); err != nil {
105105
// Handle PasswordPoliciesNotMet error
106106
}
107107
}

0 commit comments

Comments
 (0)