-1

i have mysql table with users, where i need to change user passwords. It will change with the same password for all, but it need to exclude some users.

The rule for exclude is column "lastvisitDate" with value "0000-00-00 00:00:00"

I tried to run this script, but it changed all my users..

select id FROM f5r6t_users WHERE lastvisitDate ='0000-00-00 00:00:00' ;
set password ='pass' 

Where i have a mistake? Thanks for any advice

Adamo
  • 121
  • 1
  • 6
  • That query would not have changed anything?? – RiggsFolly Apr 22 '21 at 08:42
  • What have you tried so far? Where are you stuck? Why not use an `UPDATE` query for this? Also, you should start storing encrypted passwords - now. – Nico Haase Apr 22 '21 at 08:44
  • BTW do not store passwords, never, ever. Store sha1 or md5 versions and compare them on login. – Nikolay Shindarov Apr 22 '21 at 09:21
  • 1
    @NikolayShindarov One should not use `md5` or `sha1` for passwords as they're weak algorithms (`md5`'s own [manual page](https://www.php.net/manual/en/function.md5) warns against it at the very start). The right way is to use the [built-in hashing functions](https://stackoverflow.com/questions/30279321/how-to-use-phps-password-hash-to-hash-and-verify-passwords). – El_Vanja Apr 22 '21 at 16:00

1 Answers1

2

I am not sure if I understand your question right. But I think you need an update statement.

If all users with a different lastvisitDate than '0000-00-00 00:00:00' should be updated use:

UPDATE f5r6t_users SET password = 'pass' WHERE lastvisitDate != '0000-00-00 00:00:00'

If all users with lastvisitDate '0000-00-00 00:00:00' should be updated use:

UPDATE f5r6t_users SET password = 'pass' WHERE lastvisitDate = '0000-00-00 00:00:00'
  • Logic suggests that the change will be aimed at those that have never logged in so maybe `!=` should be `=` – RiggsFolly Apr 22 '21 at 08:48
  • The rule for exclude is column "lastvisitDate" with value "0000-00-00 00:00:00" For me this sounded like every user with a different lastvisitDate shoud be updated. But I might be wrong. – Dominic Wurzer Apr 22 '21 at 08:50
  • I am guessing thats a English is not my first language issue, oh and the OP answered their own question since – RiggsFolly Apr 22 '21 at 08:51
  • Yeah...I included the other version. But I think you are right. There might be an language issue. – Dominic Wurzer Apr 22 '21 at 08:55