novice
novice

Reputation: 51

user and password authentication

i am very new to coding so i need help.i have built an application in netbeans that is connected to a database where i can store and retrieve customers details. what i am trying to do now is get a user put in a login and password before they can proceed. so in my database i have a table called LoginPassword which stores(as u can guess) user login and password. what i need help with is a bit of code that compares login and password that user put in with login and password in my database.where should i start?

Upvotes: 0

Views: 2726

Answers (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 {
        }

Upvotes: 0

NPKR
NPKR

Reputation: 5506

Make one table with name 'users'. which contains 'username' and 'password'

After click on Login Button fire a query to 'users' table to get the user record is there are not. if it is there with same 'username' and 'password' which was enterd in Login Screen then navigate to details screen else show failure message.

Upvotes: 1

Related Questions