【问题标题】:user and password authentication用户和密码认证
【发布时间】:2012-12-06 15:50:42
【问题描述】:

我对编码非常陌生,所以我需要帮助。我在 netbeans 中构建了一个应用程序,该应用程序连接到一个数据库,我可以在其中存储和检索客户详细信息。我现在要做的是让用户输入登录名和密码,然后才能继续。所以在我的数据库中,我有一个名为 LoginPassword 的表,它存储(你可以猜到)用户登录名和密码。我需要帮助的是一些代码,它将用户输入的登录名和密码与我的数据库中的登录名和密码进行比较。我应该从哪里开始?

【问题讨论】:

标签: java database netbeans


【解决方案1】:

制作一张名为“users”的表。其中包含“用户名”和“密码”

点击登录按钮后,对“用户”表进行查询以获取用户记录是否不存在。如果在登录屏幕中输入的“用户名”和“密码”相同,则导航到详细信息屏幕,否则显示失败消息。

【讨论】:

    【解决方案2】:
    String username= request.getParamaeter("username");
    String passowrd= request.getParamaeter("passowrd");
    Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection ("jdbc:mysql://localhost:3306/aeses","root","password");
                Statement stmt = con.createStatement();
                ResultSet rs = stmt.executeQuery("SELECT * from loginPassword");
                while (rs.next()){
                    if(username.equals(rs.getString("username")))
                    {
                        System.out.print("username matched");
    if(username.equals(rs.getString("password")))
                    {
                        System.out.print("password matched you can redirect to home page here");
    
                    }
                    }
                    else
                    {
                        System.out.println("Date changed");
                    }
                    temp = rs.getString(1);
                    System.out.println("Current Max Date is ===>>>"+rs.getString(1));
                }*/
            }
            /*catch (SQLException e) {
                e.printStackTrace();
            }*/
            catch (Exception e) {
                e.printStackTrace();
            }
            finally {
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-18
      相关资源
      最近更新 更多