aboutsummaryrefslogtreecommitdiffhomepage
path: root/storage
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-04-29 17:04:23 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-04-29 17:04:43 -0700
commitb166ceaea72dc6db77467621ffc270fbdccb6566 (patch)
treed0e9c96cf6e4255196332bc9bae07e79b88a83c8 /storage
parentf49b42f70f902d4da1e0fa4080e99164b331b716 (diff)
Avoid people to unlink their OAuth2 account without having a local password
Diffstat (limited to 'storage')
-rw-r--r--storage/user.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/storage/user.go b/storage/user.go
index fea59d4..de58c09 100644
--- a/storage/user.go
+++ b/storage/user.go
@@ -339,6 +339,24 @@ func (s *Storage) CheckPassword(username, password string) error {
return nil
}
+// HasPassword returns true if the given user has a password defined.
+func (s *Storage) HasPassword(userID int64) (bool, error) {
+ var result bool
+ query := `SELECT true FROM users WHERE id=$1 AND password <> ''`
+
+ err := s.db.QueryRow(query, userID).Scan(&result)
+ if err == sql.ErrNoRows {
+ return false, nil
+ } else if err != nil {
+ return false, fmt.Errorf("unable to execute query: %v", err)
+ }
+
+ if result {
+ return true, nil
+ }
+ return false, nil
+}
+
func hashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(bytes), err