简体   繁体   English

如何以登录形式获取失败的用户或密码消息

[英]how to get fail user or password message in login form

Hi i am trying to get a message says username or password is wrong when i type fail login info but the system crashes when i do that! 您好,我尝试收到一条消息,提示我输入失败的登录信息时用户名或密码错误,但这样做时系统崩溃! it work perfect when i login in with right login info, but not when i type wrong user or password, the system will crash though. 当我使用正确的登录信息登录时,它可以完美工作,但是当我键入错误的用户名或密码时,它不能正常运行。

private void btnLogInActionPerformed(java.awt.event.ActionEvent evt) {                                          



 if (projekt.Validering.textNotEmpty(tfUser) && Validering.textNotEmpty(tfPassword)){ 

   try 
     {  
     String name = tfUser.getText();  
     String password = new String(tfPassword.getPassword());  
     String allName = db.fetchSingle("SELECT PASSWORD FROM TEACHER where FORNAME = '"+name+"';");  
     String admin = db.fetchSingle("SELECT ADMINISTRATOR FROM TEACHER WHERE FORNAME ='"+name+"';");  



     if (allName.equals(password) && admin.equals("T"))  
    {  
        JOptionPane.showMessageDialog(rootPane, "you login as admin");  

        adminPagea = new adminPage(db); 
        a.setVisible(true);  
        this.dispose();  

    }  
    else if (allName.equals(password) && admin.equals("F")) 
    {  

        JOptionPane.showMessageDialog(rootPane, "you login as teacher");



        teacherPage ls = new teacherPage(db);  

         ls.setVisible(true);  

        this.dispose();  



    } else  

         JOptionPane.showMessageDialog(rootPane, "wrong user or password try again!");  



     } catch (InfException e) {

         JOptionPane.showMessageDialog(rootPane, "something went wrong!: " + e); 

}                                         
}
}

errors when the system crashes 系统崩溃时的错误

enter code here
run:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at projekt.teacherPage.btnLoggInActionPerformed(teacherPage.java:171)
    at projekt.teacherPage.access$200(teacherPage.java:22)
    at projekt.teacherPage$3.actionPerformed(teacherPage.java:132)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6533)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6298)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
BUILD SUCCESSFUL (total time: 13 seconds)

you say this code works fine in case the username and password are correct. 您说该代码在用户名和密码正确的情况下可以正常工作。 but there is some error in your variable name: 但是您的变量名存在一些错误:

String namn;

and then you use it as name. 然后使用它作为名称。

in the case its just a typo and original code uses correct variable name in that case i think your problem is that you are invoking function on a null object . 在这种情况下,它只是一个拼写错误,并且原始代码使用正确的变量名,在这种情况下, 我认为您的问题是您正在对空对象调用函数

when you enter wrong username and password in that case the following lines : 当您输入错误的用户名和密码时,以下几行:

String allName = db.fetchSingle("SELECT PASSWORD FROM TEACHER where FORNAME = '"+name+"';");  
     String admin = db.fetchSingle("SELECT ADMINISTRATOR FROM TEACHER WHERE FORNAME ='"+name+"';"); 

return null values which are assigned to the allName and admin . 返回分配给allName和admin的空值

after that you call some function on these variables in following lines : 之后,在以下几行中对这些变量调用一些函数:

if (allName.equals(password) && admin.equals("T")) 

in this case allName is null and you are trying to invoke a function on a null object. 在这种情况下,allName为null,并且您试图在null对象上调用函数。

try updating your code : 尝试更新您的代码:

private void btnLogInActionPerformed(java.awt.event.ActionEvent evt) {                                          



 if (projekt.Validering.textNotEmpty(tfUser) && Validering.textNotEmpty(tfPassword)){ 

   try 
     {  
     String name = tfUser.getText();  
     String password = new String(tfPassword.getPassword());  
     String allName = db.fetchSingle("SELECT PASSWORD FROM TEACHER where FORNAME = '"+name+"';");  
     String admin = db.fetchSingle("SELECT ADMINISTRATOR FROM TEACHER WHERE FORNAME ='"+name+"';");  


     if((allName!=null)&&(admin!=null))
     {

             if (allName.equals(password) && admin.equals("T"))  
             {  
                 JOptionPane.showMessageDialog(rootPane, "you login as admin");  
                 adminPagea = new adminPage(db); 
                 a.setVisible(true);  
                 this.dispose();  
            }  
            else if (allName.equals(password) && admin.equals("F")) 
            {  
                 JOptionPane.showMessageDialog(rootPane, "you login as teacher");
                 teacherPage ls = new teacherPage(db);  
                 ls.setVisible(true); 
                 this.dispose();  
             }
     }
     else  
     {
            JOptionPane.showMessageDialog(rootPane, "wrong user or password try again!");  
     }     

     } 

     catch (InfException e)
      {
         JOptionPane.showMessageDialog(rootPane, "something went wrong!: " + e); 

      }                                         
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用户输入错误密码后,验证信息未以登录形式显示 - Validation message not being displayed in login form when the user enters wrong password 密码错误时,登录表单不显示验证消息 - Login form doesn't display validation message when password is wrong Spring和Java Encoder中数据库密码和用户登录密码的安全性如何? - Security for DataBase password and user login password in Spring and Java Encoder How to? 如何在spring security authenticated登录中获取用户输入的用户名和密码值 - How to get the user entered values of username and password in a spring security authenticated login 如何在github登录页面上提取错误消息``用户名或密码错误'' - How to extract the error message 'Incorrect username or password' on github login page 更改密码后如何以编程方式验证用户身份? 使用j_security_check进行基于表单的身份验证来登录 - How to programatically authenticate user after changing password? Form-based authentication using j_security_check was used to login 如何在用户登录失败时重新进入 - How to make it re-enter when user login fail 如何获取模式或密码写错的消息 - How get message that the pattern or the password written wrong GWT-登录表单-如果用户名/密码不正确,浏览器总是要求记住密码事件 - GWT - login form - browser always asks to remember password event if user/password is incorrect 如何保护从Java表单应用程序登录SQL Server的密码 - How to secure password for SQL Server login from a java form application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM