2016-07-29 10 views
1

パスワードの長さ(8文字以上)、小文字と大文字、数字、特殊文字のパスワードをチェックし、それがどのレベルか、弱いかを確認するパスワード強度チェッカーGUIを作成しようとしています、strong etc ...これはmd5ハッシュを作成し、これを表示します。このハッシュをテキストファイルに保存することができます。その後、パスワードをもう一度入力し、テキストファイルから確認します(これについてのコードはまだありません)。Python tkinterパスワード強度チェッカーgui

私は強度チェック、ハッシュ生成、ファイルへのログを達成することができました。私はそう思います。パスワードが入力されていない場合、私はコードが 'パスワードは空白にすることはできません'を返すようにしたいと思いますが、GUIではうまくいきません。同じコードはシェル内で動作します。このコードでは、たとえ3文字しかパスワードとして使用されていない場合でも、強度として「非常に弱い」を返すことはありません。ここで

は、これまでの私のコードです:

from tkinter import * 
import hashlib 
import os 
import re 

myGui = Tk() 
myGui.geometry('500x400+700+250') 
myGui.title('Password Generator') 
guiFont = font = dict(family='Courier New, monospaced', size=18, color='#7f7f7f') 


#====== Password Entry ========== 
eLabel = Label(myGui, text="Please Enter you Password: ", font=guiFont) 
eLabel.grid(row=0, column=0) 
ePassword = Entry(myGui, show="*") 
ePassword.grid(row=0, column=1) 



#====== Strength Check ======= 


def checkPassword(): 
    strength = ['Password can not be Blank', 'Very Weak', 'Weak', 'Medium', 'Strong', 'Very Strong'] 
    score = 1 
    password = ePassword.get() 

    if len(password) < 1: 
     return strength[0] 

    if len(password) < 4: 
     return strength[1] 

    if len(password) >= 8: 
     score += 1 

    if re.search("[0-9]", password): 
     score += 1 

    if re.search("[a-z]", password) and re.search("[A-Z]", password): 
     score += 1 

    if re.search(".", password): 
     score += 1 

    passwordStrength.set(strength[score]) 

passwordStrength = StringVar() 
checkStrBtn = Button(myGui, text="Check Strength", command=checkPassword, height=2, width=25, font=guiFont) 
checkStrBtn.grid(row=2, column=0) 
checkStrLab = Label(myGui, textvariable=passwordStrength) 
checkStrLab.grid(row=2, column=1, sticky=W) 

#====== Hash the Password ====== 


def passwordHash(): 
    hash_obj1 = hashlib.md5() 
    pwmd5 = ePassword.get().encode('utf-8') 
    hash_obj1.update(pwmd5) 
    md5pw.set(hash_obj1.hexdigest()) 

md5pw = StringVar() 
hashBtn = Button(myGui, text="Generate Hash", command=passwordHash, height=2, width=25, font=guiFont) 
hashBtn.grid(row=3, column=0) 
hashLbl = Label(myGui, textvariable=md5pw) 
hashLbl.grid(row=3, column=1, sticky=W) 


#====== Log the Hash to a file ======= 


def hashlog(): 
    loghash = md5pw.get() 

    if os.path.isfile('password_hash_log.txt'): 
     obj1 = open('password_hash_log.txt', 'a') 
     obj1.write(loghash) 
     obj1.write("\n") 
     obj1.close() 

    else: 
     obj2 = open('password_hash_log.txt', 'w') 
     obj2.write(loghash) 
     obj2.write("\n") 
     obj2.close() 

btnLog = Button(myGui, text="Log Hash", command=hashlog, height=2, width=25, font=guiFont) 
btnLog.grid(row=4, column=0) 

#====== Re enter password and check against stored hash ====== 
lblVerify = Label(myGui, text="Enter Password to Verify: ", font=guiFont) 
lblVerify.grid(row=5, column=0, sticky=W) 

myGui.mainloop() 

すべてのヘルプははるかに高く評価されるだろう。ありがとう。

答えて

1

checkPassword関数の結果があります。パスワードが4文字または1文字未満の場合、return文として返されます。 checkPasswordの結果に変数が割り当てられていないので、これら2つのケースでは関数からデータを受け取ることができません。私はもっ​​と好きなものを提案したいと思う:

from tkinter import * 
import hashlib 
import os 
import re 

myGui = Tk() 
myGui.geometry('500x400+700+250') 
myGui.title('Password Generator') 
guiFont = font = dict(family='Courier New, monospaced', size=18, color='#7f7f7f') 


#====== Password Entry ========== 
eLabel = Label(myGui, text="Please Enter you Password: ", font=guiFont) 
eLabel.grid(row=0, column=0) 
ePassword = Entry(myGui, show="*") 
ePassword.grid(row=0, column=1) 



#====== Strength Check ======= 


def checkPassword(): 
    strength = ['Password can not be Blank', 'Very Weak', 'Weak', 'Medium', 'Strong', 'Very Strong'] 
    score = 1 
    password = ePassword.get() 
    print password, len(password) 

    if len(password) == 0: 
     passwordStrength.set(strength[0]) 
     return 

    if len(password) < 4: 
     passwordStrength.set(strength[1]) 
     return 

    if len(password) >= 8: 
     score += 1 

    if re.search("[0-9]", password): 
     score += 1 

    if re.search("[a-z]", password) and re.search("[A-Z]", password): 
     score += 1 

    if re.search(".", password): 
     score += 1 

    passwordStrength.set(strength[score]) 

passwordStrength = StringVar() 
checkStrBtn = Button(myGui, text="Check Strength", command=checkPassword, height=2, width=25, font=guiFont) 
checkStrBtn.grid(row=2, column=0) 
checkStrLab = Label(myGui, textvariable=passwordStrength) 
checkStrLab.grid(row=2, column=1, sticky=W) 

#====== Hash the Password ====== 


def passwordHash(): 
    hash_obj1 = hashlib.md5() 
    pwmd5 = ePassword.get().encode('utf-8') 
    hash_obj1.update(pwmd5) 
    md5pw.set(hash_obj1.hexdigest()) 

md5pw = StringVar() 
hashBtn = Button(myGui, text="Generate Hash", command=passwordHash, height=2, width=25, font=guiFont) 
hashBtn.grid(row=3, column=0) 
hashLbl = Label(myGui, textvariable=md5pw) 
hashLbl.grid(row=3, column=1, sticky=W) 


#====== Log the Hash to a file ======= 


def hashlog(): 
    loghash = md5pw.get() 

    if os.path.isfile('password_hash_log.txt'): 
     obj1 = open('password_hash_log.txt', 'a') 
     obj1.write(loghash) 
     obj1.write("\n") 
     obj1.close() 

    else: 
     obj2 = open('password_hash_log.txt', 'w') 
     obj2.write(loghash) 
     obj2.write("\n") 
     obj2.close() 

btnLog = Button(myGui, text="Log Hash", command=hashlog, height=2, width=25, font=guiFont) 
btnLog.grid(row=4, column=0) 

#====== Re enter password and check against stored hash ====== 
lblVerify = Label(myGui, text="Enter Password to Verify: ", font=guiFont) 
lblVerify.grid(row=5, column=0, sticky=W) 

myGui.mainloop() 
+0

私は年を取って頭を掻いてきた。私はそれがテストに使用されたと思いますので、自分のコードのcheckPasswordでプリントを削除しました。 – JSmith

+0

おっと、申し訳ありません。確かにそれだった:)私はそれを削除するつもりだった。 – RandomHash

関連する問題