You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pwn.go 751B

12345678910111213141516171819202122232425262728
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package password
  4. import (
  5. "context"
  6. "code.gitea.io/gitea/modules/password/pwn"
  7. "code.gitea.io/gitea/modules/setting"
  8. )
  9. // IsPwned checks whether a password has been pwned
  10. // NOTE: This func returns true if it encounters an error under the assumption that you ALWAYS want to check against
  11. // HIBP, so not getting a response should block a password until it can be verified.
  12. func IsPwned(ctx context.Context, password string) (bool, error) {
  13. if !setting.PasswordCheckPwn {
  14. return false, nil
  15. }
  16. client := pwn.New(pwn.WithContext(ctx))
  17. count, err := client.CheckPassword(password, true)
  18. if err != nil {
  19. return true, err
  20. }
  21. return count > 0, nil
  22. }