Version: 1.00, by dlst
Developer Last Online: Jan 2004
Version: 2.2.x
Rating:
Released: 01-26-2002
Last Update: Never
Installs: 10
No support by the author.
Hi all.
I have a client that runs a board that has about 100 members that are his personal friends, and the other 3400 members are just regular users. Lately poeple have been registering with usernames very similar to those of his friends, and his friends are complaining.
He asked me for a way to display a list of usernames that "sound like" or "are similar to" existing users, so that when he moderates user registrations it's easy to make a decision as to allow the new user or not.
Anyway, this VERY simple hack searches the database for existing usernames, and checks to see if they are similar to the username that is being registered. If it finds any, it simply lists them.
The system uses my own combination of metaphone and levenshtein to try to find similar matches.
There are options in the code to limit the number of returned matches, and to set the "tolerance level" of the search. A higher tolerance allows more matches.
Did I mention this was an EXCEEDINGLY simple hack? The only modifications are to admin/user.php.
You need to add two bits of code. The first is around line 1182, when you see the following code:
PHP Code:
$users=$DB_site->query("SELECT userid,username,email FROM user WHERE usergroupid=4 ORDER BY username");
Add this AFTER the code above:
PHP Code:
// DLST hack! Show similar usernames when moderating a user signup
// to speed things up, get an array of all the users in the system here
$sim_all_users=$DB_site->query("SELECT username FROM user WHERE usergroupid!=4");
while ($sim_all_user=$DB_site->fetch_array($sim_all_users)) {
$sim_arr_all_users[] = $sim_all_user[username];
}
// now we have $sim_arr_all_users, an array with all the usernames in the system that a current
// END
Then, find the following (a couple lines down, around 1190):
// DLST hack! Show similar usernames when moderating a user signup
//********************
// Options for Show Similar Usernames Hack
$sim_limit_show = 10; // maximum number of similar names to show
$sim_tolerance = 2; // how close a match to the username do you want? The lower it is, the closer
// the usernames must match to show up in list. Experiment for yourself, but
// this number works best for me.
// END Options
//********************
// $user[username] is the username trying to get registered
// $sim_message is the list of similar usernames that gets generated
$sim_meta1 = metaphone( $user[username] ); // get the metaphone for the username we are checking
reset ($sim_arr_all_users); // reset the array
while ( $sim_thiscount < $sim_limit_show && list(, $sim_current_user) = each ($sim_arr_all_users) ) {
$sim_meta2 = metaphone( $sim_current_user ); // get the metaphone for the usernames that already exist
$sim_score = levenshtein( $sim_meta1, $sim_meta2 ); // generate a score with the lev. method
if ( $sim_score <= $sim_tolerance ) { // compare the score to the tolerance (set above)
$sim_users_found[] = $sim_current_user; // if it's good, add it to the list
$sim_thiscount++; // increase the count of matched usernames by one
}
}
if ( $sim_thiscount > 0 ) {
$sim_message = "A total of $sim_thiscount similar users were found: ";
foreach ($sim_users_found as $sim_value) {
$sim_message .= "<b>$sim_value</b>, ";
}
$sim_message = substr( $sim_message, 0, -2 ); // remove the last comma
} else {
$sim_message = "No similar usernames were found in the user list.";
}
And that's it! Moderate a user registration to see it in action.
I'd very much like to get as much feedback as possible for this, so don't hold back! If you have any suggestions, or ways to optimize the code further, also let me know.
-DLST
Show Your Support
This modification may not be copied, reproduced or published elsewhere without author's permission.
Originally posted by dlst Hi all.
[...]
I'd very much like to get as much feedback as possible for this, so don't hold back! If you have any suggestions, or ways to optimize the code further, also let me know.
-DLST
Thanks a lot for having shared your work.
Is there any way to extend the searchin' for dupes also to email and IPs, giving out the same list of dupe usernames (for instance, specifying which would the matching field...) ?
(as we discussed in Beta releases)
Would this hack work if moderating new users isn't in effect? (affect?) I don't moderate my new members, but it would be good to display similar usernames for them to see before they decide on a name. Also, will this work in conjuction with PPN's "Name Checker" hack?
Originally posted by Rose Would this hack work if moderating new users isn't in effect? (affect?) I don't moderate my new members, but it would be good to display similar usernames for them to see before they decide on a name. Also, will this work in conjuction with PPN's "Name Checker" hack?
No, this hack will not work if you are not moderating new users. It could be modified to work the way you would like, but that's not what it's designed for in this implementation. However, even if you're not a great programmer, you shouldn't have any trouble just cutting and pasting the code to wherever you like and adapting it to your needs. You're welcome to do that.
I have not tested this in conjunction with PPN's "Name Checker" hack, in fact I've never heard of that one. Sorry.
[...] However, even if you're not a great programmer, you shouldn't have any trouble just cutting and pasting the code to wherever you like and adapting it to your needs. You're welcome to do that.
Hi, Dlst. Are you there...
Well, as you know, I would need an enhancement of the hack like we talked a lot about.
So, I'm trying to realize it myself learning something about php seek... This way, hope it shouldn't a problem to you ?
Even not too much requested, at the end I would publish here my hack based on yours (actually it's based only upon the junction between metaphone() and levenstein()), even I made a lot of variants to manage short words which should become false alarms. Also the interface is much different as I'll list in a new page and more...
What do you think about ?