reset_password.go 811 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package cli // import "miniflux.app/cli"
  5. import (
  6. "fmt"
  7. "os"
  8. "miniflux.app/storage"
  9. )
  10. func resetPassword(store *storage.Storage) {
  11. username, password := askCredentials()
  12. user, err := store.UserByUsername(username)
  13. if err != nil {
  14. fmt.Fprintf(os.Stderr, "%v\n", err)
  15. os.Exit(1)
  16. }
  17. if user == nil {
  18. fmt.Fprintf(os.Stderr, "User not found!\n")
  19. os.Exit(1)
  20. }
  21. user.Password = password
  22. if err := user.ValidatePassword(); err != nil {
  23. fmt.Fprintf(os.Stderr, "%v\n", err)
  24. os.Exit(1)
  25. }
  26. if err := store.UpdateUser(user); err != nil {
  27. fmt.Fprintf(os.Stderr, "%v\n", err)
  28. os.Exit(1)
  29. }
  30. fmt.Println("Password changed!")
  31. }