Simple User Authentication Login using Java
This tutorial will teach you how to make a simple login form without using the database, it simply authenticate the input of the user using the Selection Structure If Statement.
So first, let’s set up a new project, choose Java Application, set your Project Name, Location and Folder Name and click Finish.
Step 1:
Add 3 JLabels(Edit Text: Login Form, Username, Password)
Add 1 JTextField and 1 JPasswordField(Change Variable Name: tfUsername, pfPassword)
Add 2 JButtons(Edit Text: Login, Reset. Change Variable Name: bLogin, bReset)
Add 1 JCheckBox(Edit Text: Remember Password. Change Variable Name: chkRemember)
Add 1 JLabel(Change Variable Name: lMessage)
So first, let’s set up a new project, choose Java Application, set your Project Name, Location and Folder Name and click Finish.
Step 1:
Add 3 JLabels(Edit Text: Login Form, Username, Password)
Add 1 JTextField and 1 JPasswordField(Change Variable Name: tfUsername, pfPassword)
Add 2 JButtons(Edit Text: Login, Reset. Change Variable Name: bLogin, bReset)
Add 1 JCheckBox(Edit Text: Remember Password. Change Variable Name: chkRemember)
Add 1 JLabel(Change Variable Name: lMessage)
Format of Login Form
Label: Font – Tahoma 24, Bold. Foreground – 0,0,255
Step 2:
Code:
private void bLoginActionPerformed(java.awt.event.ActionEvent evt) {if (tfUsername.getText().equalsIgnoreCase("admin") && pfPassword.getText().equalsIgnoreCase("admin")){if (chkRemember.isSelected()){lMessage.setText("Login Successfull with remembering option");}else{lMessage.setText("Login Successfull without remembering option");}}else{lMessage.setText("Login Failed!");}}private void bResetActionPerformed(java.awt.event.ActionEvent evt) {tfUsername.setText(null);pfPassword.setText(null);lMessage.setText(null);chkRemember.setSelected(false);}
Final Output:
Simple User Authentication Login using Java
Reviewed by code-dev
on
3:22 PM
Rating:
No comments: