DEV Community

loading...

Discussion on: Daily Challenge #300 - Username / Password Comparison

Collapse
peter279k profile image
peter279k

Here is the simple solution with Python and difflib module:

import difflib


def validate(username, password):
    if len(username) == 0 and len(password) == 0:
        return False
    if len(username) == 0 or len(password) == 0:
        return False
    limit = min([len(password), len(username)]) / 2

    matches = difflib.SequenceMatcher(None, username, password).get_matching_blocks()
    size = 0
    for match in matches:
        if match.size >= limit:
            size += match.size

    if size == 0:
        return True
    return False
Enter fullscreen mode Exit fullscreen mode