2017-03-16 20 views
0

は、同じ 'username'と 'password'でのみ動作します!私はそれがうまくいくようにしたい場合は、 'username'は、 'パスワード'リストからstrに一致するようにしても、それは動作している..ヘルプ..ログインフォームが機能しません!このログインフォームのpython

 self.usernamelist = ['aniruddh','firoz','ashish'] 
     self.passwordlist = ['aniruddh','firoz','ashish'] 

     self.connect(self.okbutton, SIGNAL("clicked()"),self.loginfunction) 


    def loginfunction(self): 
     usernamestatus = False 
     usernameindex = -1 
     passwordstatus = False 
     passwordindex = -1 
     for currentusername in range(len(self.usernamelist)): 
      if self.passwordlist[currentusername] == self.username.text(): 
       usernamestatus = True 
       usernameindex = self.usernamelist.index(self.passwordlist[currentusername]) 

     for currentpassword in range(len(self.passwordlist)): 
      if self.usernamelist[currentpassword] == self.password.text(): 
       passwordstatus = True 
       passwordindex = self.passwordlist.index(self.usernamelist[currentpassword]) 

     if usernamestatus == True and passwordstatus ==True and usernameindex: #== passwordindex: 
      self.hide() 
      w2 = chooseoption.Form1(self) 
      w2.show() 


     else: 

         self.msgBox = QMessageBox() 
         self.msgBox.setWindowTitle("Alert!") 
         self.msgBox.setWindowIcon(QtGui.QIcon('abcd.ico')) 
         self.msgBox.setText("Unauthorised User!!!") 
      self.msgBox.exec_() 

答えて

0

問題は、パスワードを確認するときに、パスワードがユーザーネームリストに含まれているかどうかを確認することです。あなたがする必要があるのは:
1ユーザー名がリストに存在するかどうかを確認します。
2パスワードがそのユーザー名に有効かどうかを確認します。その場合、passwordlistのindex [i]のパスワードはusernamelistの同じインデックスのユーザー名に有効です。

だから、ログイン機能は次のように考えられます。

def loginfunction(self): 
    usernameindex = -1 
    passwordindex = -1 
    username = self.username.text() 
    password = self.password.text() 
    if username in self.usernamelist: # 1- check: if the username is in the list 
     usernameindex = self.usernamelist.index(username) # then: get the index of the username 
     if password == self.passwordlist[usernameindex]: # 2- check: if password is equal to the password in passwordlist on the same index of the username 
      self.hide() 
      w2 = chooseoption.Form1(self) 
      w2.show() 
     else: # if the password is not correct 
      self.msgBox = QMessageBox() 
      self.msgBox.setWindowTitle("Alert!") 
      self.msgBox.setWindowIcon(QtGui.QIcon('abcd.ico')) 
      self.msgBox.setText("Incorrect password!!!") 

    else: # the username is not in the list 
     self.msgBox = QMessageBox() 
     self.msgBox.setWindowTitle("Alert!") 
     self.msgBox.setWindowIcon(QtGui.QIcon('abcd.ico')) 
     self.msgBox.setText("Unauthorised User!!!") 
+0

年代そんなにありがとう! –

関連する問題