Skip to content

Commit

Permalink
Make rodauth.has_password? method public
Browse files Browse the repository at this point in the history
I needed this method when integrating rodauth-omniauth into our project.

If an account is created via omniauth, it doesn't have a password. In
this case, I prefer to display "Create Password" instead of "Change
Password".

Additionally, if the omniauth provider is the last authentication
method, including the password, I aim to block to disconnect it.

Therefore, I believe this method is beneficial to have in public.
  • Loading branch information
enescakir authored and jeremyevans committed Dec 26, 2024
1 parent 3921088 commit bb37118
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
=== master
* Make rodauth.has_password? method public (enescakir) (#461)

* Fix strict_unused_block warnings when running specs on Ruby 3.4 (jeremyevans)

Expand Down
12 changes: 6 additions & 6 deletions lib/rodauth/features/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ def possible_authentication_methods
has_password? ? ['password'] : []
end

def has_password?
return @has_password if defined?(@has_password)
return false unless account || session_value
@has_password = !!get_password_hash
end

private

def _around_rodauth
Expand Down Expand Up @@ -718,12 +724,6 @@ def function_name(name)
end
end

def has_password?
return @has_password if defined?(@has_password)
return false unless account || session_value
@has_password = !!get_password_hash
end

def password_hash_using_salt(password, salt)
BCrypt::Engine.hash_secret(password, salt)
end
Expand Down

0 comments on commit bb37118

Please sign in to comment.