0

I've created a program to take in a password and tell the user by how many characters the password is wrong. To do this I've used difflib.Differ().

However I'm not sure how to create another loop to make it also be able to tell my how many characters the password is wrong if the input is missing characters.

This is the checking function itself.

import difflib

def check_text(correctPass, inputPass):
    count = 0
    difference = 0
    d = difflib.Differ()
    count_difference = list(d.compare(correctPass, inputPass))
    while count < len(count_difference):
        if '+' in count_difference[count]:
            difference +=1                
        count +=1
    return difference

At the moment the function can only pick up mistakes if the mistakes are extra characters (correct password in this case is 'rusty').

My understanding of difflib is quite poor. Do I create a new loop, swap the < for a > and the +s for -s? Or do I just change the conditions already in the while loop?

EDIT: example input/output: rusty33 –> wrong by 2 characters rsty –> wrong by 0 characters

I'm mainly trying to make the function detect if there are characters missing or extra, not too fussed about order of characters for the moment.

Cyanidies
  • 57
  • 1
  • 2
  • 9
  • Look at https://en.wikipedia.org/wiki/Levenshtein_distance as a related topic to what you are trying to do – vav Jul 29 '16 at 13:42
  • Do you have to use `difflib`? Also can you give us sample input/output and explain what makes the characters extra/different? Does being out of order matter, etc.? – Bahrom Jul 29 '16 at 13:44

0 Answers0