How to verify username and password in Java-mysql? -



How to verify username and password in Java-mysql? -

how verify in right way username , password inputted user database?

in c++, used verify using if-else: if((user == "username")&&(pass == "password")){ cout<<"you logon!"; }

in java-mysql i'm not sure if i'm on right track:

login button

private void jbutton1actionperformed(java.awt.event.actionevent evt) { // todo add together handling code here: user = jtextfield1.gettext(); pass = jpasswordfield1.getpassword(); login(); }

method/function

private void login() { seek { if (user != null) { sql = "select * users_table username='" + user + "'"; rs = stmt.executequery(sql); rs.next(); username = rs.getstring("username"); password = rs.getstring("password"); } } grab (sqlexception err) { joptionpane.showmessagedialog(this, err.getmessage()); } }

if username , password inputted user matched ones in database directed new jframe else message dialog popup saying invalid username or password. can help me codes, don't know how utilize if-else statement mysql;

thanks! :)

implement below code:

private void login() { seek { if (user != null && pass != null) { string sql = "select * users_table username='" + user + "' , password='" + pass + "'"; rs = stmt.executequery(sql); if (rs.next()) { //in case come in when @ to the lowest degree 1 result comes means user valid } else { //in case come in when result size 0 means user invalid } } // can validate user result size if comes 0 user invalid else user valid } grab (sqlexception err) { joptionpane.showmessagedialog(this, err.getmessage()); } }

java passwords

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -