Java Servlet
Program that represents an authentication platform
where user
will
authenticate their username,
passwordand
usercode.
After
successful authentication,
a
message
will be printed on the screen. All the wrong use of credentials
will result in error that you will handle and there will
also
be
a message displayed
on the screen.
Following
are minimum guidelines:
1. The front end should have a background color
and a heading like “User authentication System”.
2.
It should have
a text field with label ‘username’
where user will
enter username, a text field with label ‘password’ where user will
enter password, a text field with label
usercode
where user will enter a
usercode
and a submit button with label
‘Submit’.
3.
Initially
all text fields will be blank and no color. User enters a wrong
username, a message will be printed on the front end “You entered
wrong username, please try again”, and the color of the ‘username’
text field will turn red. When a correct username is entered, the
color of text field will turn green. This behavior should persist
for all text fields.
4.
A successful authentication should be followed by a message on the
screen stating that then
authentication is successful.
5.
User doesn’t input any value on any of the text fields and clicks
the submit button will result as an error and you should handle it.
On the front end a message should display “Please enter a
username
6.
All incorrect entry will result in an error and a message on the
front end “You entered
wrong
……..,
please try again”.
8.
Database info:
A.
Create a database “authDataBase”
B.
Create a table ‘accountinfo”
in that database with the following:
userIDusernamepasswordusercode
100
janediamjane777
101
johndjohniam888
Hi,
index.html
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8"/>
<title>User Authetication</title>
</head>
<body bgcolor="#acbbdd" style="font-size:
65px;color:#fff;text-align: center;"><p></p>
<div><b>User Authetication
System</b></div>
<div>
<form method="/index.jsp"
action="get">
<!--send form in get method to index.jsp -->
<table
style="font-size: 29px;" align="center">
<tr>
<td>Name:</td>
<td><input type="text" name="username"
placeholder="Enter your username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="Password"
name="Password" placeholder="Enter your
password"></td>
</tr>
<tr><td><input
type="Submit"></td></tr>
</table>
</form>
</div>
</body>
</html>
index.jsp
<%@ page import = "java.sql.*" %>
<%--importing java.sql.* --%>
<%@ page import = "javax.sql.*" %>
<%--importing javax.sql. --%>
<%-- getting the values from request object by getParameter
function and storing the values in user and pass,
Class.forName to call the jdbc driver for code database connection
DriverManager.getConnection to settle the connection and passing
three arguments namely, url(to which point to be hit from where the
data to be fetched in request object the, simply the url), username
(mine is root), then password(), authDataBase is the name of the
database. st a Statement object which consist of all query to be
ran in my sql and .executeQuery will run the query and storing the
data in ResultSet object. executing the query as "select * from
accountinfo where userId="+user+"and password ="+pass" will allow
to fetch only that dataset which matches with the passed value i.e.
username and password, and if valus are correct then there muct be
something returns to resultSet object and .next() will checkk this
if it contains that implies the data is correct and it is valid
user credential otherwise not. --%>
<%
String user =
request.getParameter("username");
String pass = request.getParameter("Password");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/authDataBase","root","");
Statement st = con.createStatement();
ResultSet resultSet = st.executrQuery("select * from
accountinfo where userId="+user+"and password ="+pass);
if(resultSet.next()){
out.print("Welcome"+user);
}else{
out.print("You entered wrong
..............,,,,,Please try again.");
}
%>
query.sql
create database authDataBase;
use authDataBase;
create table accountinfo(userID int,username varchar(255),password varchar(255),usercode int);
insert into accountinfo values(100,'janed','iamjane',777);
insert into accountinfo values(101,'johnd','johniam',888);
select * from accountinfo;
Get Answers For Free
Most questions answered within 1 hours.