0
Table Structure:
userid password adminlevel
  • userid is BIGINT (UNIQUE)
  • password is VARCHAR
  • adminlevel is SMALLINT

How do I write a query to get a list of users with adminlevel greater than 0 whose password is being used on other accounts?

The query result must satisfy the following conditions:

  1. adminlevel > 0
  2. there are accounts other than itself where the same password is being used

1 Answer 1

1
SELECT a.userid AS TheAdmin,
       GROUP_CONCAT(b.userid) AS NonAdminsWithSamePwd
    FROM tbl AS a
    JOIN tbl AS b  ON b.password = a.password
    WHERE a.adminlevel > 0
      AND b.adminlevel = 0
3
  • This assumes an unseeded password. That implies the passwords are not stored securely.
    – BillThor
    Commented Feb 1, 2017 at 9:24
  • This code will handle plaintext, encrypted, seeded, etc, passwords -- as long as they are consistently mangled. @BillThor - Why do you say otherwise?
    – Rick James
    Commented Feb 1, 2017 at 16:06
  • Properly seeded passwords will all have unique seeds. This will result in different password hashes for every user even if they have the same password.
    – BillThor
    Commented Feb 4, 2017 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.