Results 1 to 8 of 8
  1. #1
    kine is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Post Creating a login form using sql server 2005 database

    Hello Guys
    I'm creating a login form using java swing GUI and sql server 2005 database, i can connect to the database, but i have difficulty using created username and password in my database-security-user to login in the login GUI.

    I will appreciate assistance from guys in creating a login form that will display another GUI.

    help me out pls!

  2. #2
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    Please Present Code.
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  3. #3
    kine is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    Here is code for my database creating the username and password.

    CREATE LOGIN nayd13 WITH PASSWORD = 'welcome';
    USE SDIM;
    CREATE USER Neyds FOR LOGIN neyd13;

    now my connection to database sql server 2005 is

    try {
    Class.forName(“com.microsoft.sqlserver.jdbc.SQLSer verDriver”);

    Connection con = DriverManager.getConnection(connectionUrl);
    if(con != null)
    {System.out.println("connection sucessful");}
    else {System.out.println("no connection");}
    }
    catch (SQLException e) {
    e.printStackTrace();
    }
    catch (ClassNotFoundException cE) {
    e.printStackTrace();
    }
    which connect sucessfuly.

    well using created username and password in the database is login, which will display another Jform window application is what i'm an having diffculty writing the code for it.
    ie
    private void entBtnActionPerformed(java.awt.event.ActionEvent evt){

    Help me here pls...

    }
    using my created usename and password to login and display a new window

    thanx

  4. #4
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    So wait... write out the steps of the process you are trying to do.

    1. Login
    2. Go to new window?

    If these are your steps, In the login, on the btn you will have to use a select statement and compare your username to the one you typed in, than if correct, go to a new window.

    so you should research passing sql statements and displaying displaying new window.
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    It's not a login, as in a user table.
    He's using SQL Server security, so the login is in the connection URL...at least that's what it looks like to me?

  6. #6
    kine is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    Now i have difficulty writting out the code to reset user password in the database after login into the application.

    Here is my code

    char[] oldPass = jPasswordField1.getPassword();
    String strOldPass = new String(oldPass);

    char[] newPass = jPasswordField2.getPassword();
    String strNewPass = new String(newPass);

    char[] confPass = jPasswordField3.getPassword();
    String strConfPass = new String(confPass);

    try
    {
    Inventory objInven = new Inventory();//creating of the objectof the connection in class Inventory.

    Statement stmt = objinven.con.createStatement();
    ResultSet rs = stmt.getResult();

    while(rs.next())
    {
    if(rs.getsring("Password").equals(strOldPass))
    {
    rs.moveToInserRow();
    rs.updateString("Password", strNewPass);
    rs.updateString("Password", strConfPass);

    if(strNewPass.equals(strConfPass))
    {
    JOptionPane.showMessageDialog(this, "Password change successfuly");
    }
    else
    {JOptionPane.showMessageDialog(this, "Password do not match");
    }
    }
    else
    {
    JOptionPane.showMessageDialog(this, "Wrong old Password");

    }
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    }

    this code is to be performed when a submit button is clicked.
    i have this error : Exception occurred during event dispatching: jana.lang.NullPointerException.

    please help me out with this code that will allow users to change their old password to a new one in the database created by correcting my error

    Thanx

  7. #7
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Don't change password arrays to Strings

    Java Code:
    char[] oldPass = jPasswordField1.getPassword();
    String strOldPass = new String(oldPass);
    
    char[] newPass = jPasswordField2.getPassword();
    String strNewPass = new String(newPass);
    
    char[] confPass = jPasswordField3.getPassword();
    String strConfPass = new String(confPass);
    
    
    if(rs.getsring("Password").equals(strOldPass))
    You defeat the reason why passwords are character arrays

    do this

    Java Code:
    char oldPass[]=PasswordField1.getPassword();
    char newPass[]=jPasswordField2.getPassword();
    char confPass[]=jPassWordField3.getPassword();
    
    // check if char arrays are equal
    boolean same=Arrays.equals(newPass,confPass);
    
    // change arrays when done
    Arrays.fill(newPass, ' ');
    Arrays.fill(oldPass, ' ');
    etc..

  8. #8
    wzq110120 is offline Member
    Join Date
    May 2010
    Location
    china
    Posts
    7
    Rep Power
    0

Similar Threads

  1. SQL server 2005 - Login failed message
    By pbaudru in forum JDBC
    Replies: 15
    Last Post: 02-10-2010, 11:03 AM
  2. Replies: 0
    Last Post: 12-01-2009, 10:01 PM
  3. SWT login form
    By Sureshgurram in forum SWT / JFace
    Replies: 4
    Last Post: 09-07-2009, 03:14 PM
  4. Login form issue
    By mfayaz in forum New To Java
    Replies: 5
    Last Post: 03-27-2009, 08:35 PM
  5. Replies: 0
    Last Post: 06-25-2008, 12:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •