troubleshooting Question

How can I check for 'hashed' and 'non-hashed' password to allow users to log in?

Avatar of Adam
AdamFlag for United Kingdom of Great Britain and Northern Ireland asked on
Web DevelopmentHTMLPHP
14 Comments1 Solution130 ViewsLast Modified:
I have an existing table of users where the user passwords have not been 'hashed'. I am updating a website which will use this table, and this updated website will use the hash function.

However, the existing table just displays the passwords as normal text and are visible in the table.  

My problem is that when older (existing) users try to log in with a password which has not been hashed, they can't log in, because (I think )  the password_verify function I am using is looking for a hashed password. When it doesn't see the hashed password, logon fails.

if(password_verify($password, $teacher['password']))  //i.e.Password Match - only works with the password hash function!

I understand that for security, all passwords should now be hashed, and this will apply to new users signing up to the site. However, for existing users whose passwords are not hashed, what would be the best approach for allowing them to login with their existing password? I'm thinking along the lines of using a variation of the password_verify function which also checks non hashed passwords, and at the same time, mailing existing members and ask them to login to update their passwords - which would then 'hash them'.

So I guess my question is how do I amend my function to allow hashed and non-hashed passwords to be checked?

Many thanks,

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 14 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros