How to find users with password same as their username How do I find users which their password is equal to their username in Drupal 7?
If you are trying to do this while they are registering, there are good modules for the task, a simple search finds Password policy module, It is also on S.O:


  A password policy can be defined with a set of constraints which must be met before a user password change will be accepted. Each constraint has a parameter allowing for the minimum number of valid conditions which must be met before the constraint is satisfied.


However for already registered users, you have to hash their username as a password and compare it to their actual hash stored in database, if they are the same, you have cracked their password!

Hashing the passwords, The Druapl way user_hash_password()like this:

$user = user_load($id_of_user);
if($user-&gt;pass == user_hash_password($user-&gt;name)) {
  block_and_punush_lazy_user($user);
}

// maybe use it like this:
for($uid=2; $uid&lt; MAX_UID_IN_DB; $uid++) { // FROM 2 ONLY!!
  if($user = user_load($uid) {
    if($user-&gt;pass == user_hash_password($user-&gt;name)) .... // Punish
  }
}


A more quick solution is to do it solely in database using it's hashing functions. You should check the password.inc in user module and extract the hashing algorithm. implement the same function in mysql and do a:

SELECT `uid` FROM `users` WHERE `pass` = MY_CUSTOM_HASH_FUNC(`name`);


And DO make a backup of your database before doing these stuff.