Pārlūkot izejas kodu

implement NS PASSWD for password changes

tags/v1.0.0-rc1
Shivaram Lingamneni 5 gadus atpakaļ
vecāks
revīzija
48f9b5e4fa
2 mainītis faili ar 68 papildinājumiem un 5 dzēšanām
  1. 10
    5
      irc/accounts.go
  2. 58
    0
      irc/nickserv.go

+ 10
- 5
irc/accounts.go Parādīt failu

@@ -565,14 +565,15 @@ func (am *AccountManager) SetNickReserved(client *Client, nick string, saUnreser
565 565
 	return nil
566 566
 }
567 567
 
568
-func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName string, passphrase string) error {
569
-	account, err := am.LoadAccount(accountName)
568
+func (am *AccountManager) checkPassphrase(accountName, passphrase string) (account ClientAccount, err error) {
569
+	account, err = am.LoadAccount(accountName)
570 570
 	if err != nil {
571
-		return err
571
+		return
572 572
 	}
573 573
 
574 574
 	if !account.Verified {
575
-		return errAccountUnverified
575
+		err = errAccountUnverified
576
+		return
576 577
 	}
577 578
 
578 579
 	switch account.Credentials.Version {
@@ -583,9 +584,13 @@ func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName s
583 584
 	default:
584 585
 		err = errAccountInvalidCredentials
585 586
 	}
587
+	return
588
+}
586 589
 
590
+func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName string, passphrase string) error {
591
+	account, err := am.checkPassphrase(accountName, passphrase)
587 592
 	if err != nil {
588
-		return errAccountInvalidCredentials
593
+		return err
589 594
 	}
590 595
 
591 596
 	am.Login(client, account)

+ 58
- 0
irc/nickserv.go Parādīt failu

@@ -121,6 +121,18 @@ or other verification.`,
121 121
 			helpShort: `$bVERIFY$b lets you complete account registration.`,
122 122
 			enabled:   servCmdRequiresAccreg,
123 123
 		},
124
+		"passwd": {
125
+			handler: nsPasswdHandler,
126
+			help: `Syntax: $bPASSWD <current> <new> <new_again>$b
127
+Or:     $bPASSWD <username> <new>$b
128
+
129
+PASSWD lets you change your account password. You must supply your current
130
+password and confirm the new one by typing it twice. If you're an IRC operator
131
+with the correct permissions, you can use PASSWD to reset someone else's
132
+password by supplying their username and then the desired password.`,
133
+			helpShort: `$bPASSWD$b lets you change your password.`,
134
+			enabled:   servCmdRequiresAuthEnabled,
135
+		},
124 136
 	}
125 137
 )
126 138
 
@@ -389,3 +401,49 @@ func nsVerifyHandler(server *Server, client *Client, command, params string, rb
389 401
 
390 402
 	sendSuccessfulRegResponse(client, rb, true)
391 403
 }
404
+
405
+func nsPasswdHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
406
+	var target string
407
+	var newPassword string
408
+	var errorMessage string
409
+
410
+	fields := strings.Fields(params)
411
+	switch len(fields) {
412
+	case 2:
413
+		if !client.HasRoleCapabs("accreg") {
414
+			errorMessage = "Insufficient privileges"
415
+		} else {
416
+			target, newPassword = fields[0], fields[1]
417
+		}
418
+	case 3:
419
+		target = client.Account()
420
+		if target == "" {
421
+			errorMessage = "You're not logged into an account"
422
+		} else if fields[1] != fields[2] {
423
+			errorMessage = "Passwords do not match"
424
+		} else {
425
+			// check that they correctly supplied the preexisting password
426
+			_, err := server.accounts.checkPassphrase(target, fields[0])
427
+			if err != nil {
428
+				errorMessage = "Password incorrect"
429
+			} else {
430
+				newPassword = fields[1]
431
+			}
432
+		}
433
+	default:
434
+		errorMessage = "Invalid parameters"
435
+	}
436
+
437
+	if errorMessage != "" {
438
+		nsNotice(rb, client.t(errorMessage))
439
+		return
440
+	}
441
+
442
+	err := server.accounts.setPassword(target, newPassword)
443
+	if err == nil {
444
+		nsNotice(rb, client.t("Password changed"))
445
+	} else {
446
+		server.logger.Error("internal", fmt.Sprintf("could not upgrade user password: %v", err))
447
+		nsNotice(rb, client.t("Password could not be changed due to server error"))
448
+	}
449
+}

Notiek ielāde…
Atcelt
Saglabāt