1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-26 18:21:01 +00:00

Avoid people to unlink their OAuth2 account without having a local password

This commit is contained in:
Frédéric Guillot 2018-04-29 17:04:23 -07:00
parent f49b42f70f
commit b166ceaea7
5 changed files with 39 additions and 6 deletions

View file

@ -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