1

I run a website where users have a username. They can change their usernames whenever they want. When them change their name, we check that that name isn't currently being used and then allow or not allow the change. On our site people often like to change their username to copy other peoples (make their name very similar to confuse other people of their identity). This isn't uncommon for the type of site we run.

Is way to easily check for usernames that are somewhat similar using a simple query?

Here are some examples of usernames that we would like to have a query match up.

testingman1 = testingman11
lionhead = Iionhead (one has an l and the other has a capital i)
sleepybears = sleeepybears

Any way to do a character by character count of the same letters in the same position and then determine based on the percentage if it is a copy of another user?

I know I'll most likely have to write a custom function, but just looking for some advice on how to make it as painless and not very system taxing process.

5
  • 2
    Try: en.wikipedia.org/wiki/Levenshtein_distance Commented Jul 31, 2013 at 16:13
  • Thanks a ton! I didn't know such a thing existed! I'll pry implement the php version of it (php.net/manual/en/function.levenshtein.php). Not a big fan of creating functions in MySql. Commented Jul 31, 2013 at 16:24
  • just be careful. you may end up with false positives, e.g. two legitmately different names that do only differ by one character, like tommi and tammi. Commented Jul 31, 2013 at 16:27
  • Have a look at the soundex function: php.net/manual/en/function.soundex.php. You would use $u = soundex( $username ); $u2 = soundex( $newName ); if( $u1 == $u2 ) { then pick another name } Commented Jul 31, 2013 at 16:34
  • possible duplicate of How to match similar words? Commented Sep 3, 2013 at 15:27

1 Answer 1

1

You can use

Sign up to request clarification or add additional context in comments.

1 Comment

Loading all the data into PHP to compare it? Not very efficient. There are several implementations of levenstein for MySQL, e.g. github.com/MartinZottmann/mysql-levenshtein I expect there are other functions for string comparison too.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.