Share on Google+Share on Google+

ranireddy
lOGIN according to der roles
2 Answer(s)      5 years and a month ago
Posted in : JSP-Servlet

how to login a user according to roles and page will should be same content will be different

Ads

View Answers

February 21, 2012 at 3:22 PM


1)index.jsp:

<a href="login.jsp">User Login</a>&nbsp&nbsp&nbsp&nbsp<a href="adminPage.jsp">Admin Login</a>

2)login.jsp:

<html>
<script>
function validate(){
var username=document.form.user.value;
var password=document.form.pass.value;
if(username==""){
 alert("Enter Username!");
  return false;
}
if(password==""){
 alert("Enter Password!");
  return false;
}
return true;
}
</script>
<form name="form" method="post" action="check.jsp" onsubmit="javascript:return validate();">
<table>
<tr><td>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>
<%String msg=request.getParameter("msg");
if(msg!=null){
    %>
<label><font color="red"><%=msg%></font></label> 
<%
}
    %>

3)check.jsp:

<[email protected] import="java.sql.*"%>

<%
String user=request.getParameter("user");
String pass=request.getParameter("pass");
 Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'");
int count=0;
          while(rs.next())
          {

                   count++;
          }

                    if(count>0)
          {
            out.println("welcome "+user);
          }
          else
          {
                       response.sendRedirect("login.jsp?msg=Invalid Username or Password");
          }
%>


February 21, 2012 at 3:23 PM


continue..

4)adminPage.jsp:

<html>
<title>Admin login Page</title>
<head>
<script language="JavaScript">
function isProper(string) {

if (!string) return false;
var iChars = "*|,\":<>[]{}`\';()@&$#%";

for (var i = 0; i < string.length; i++) {
if (iChars.indexOf(string.charAt(i)) != -1)
return false;
}
return true;
}

function validateForm(theForm){
if(theForm.userid.value==""){
//Please enter accountholder
alert("Enter the User Name.");
theForm.userid.focus();
return false;
}

if (isProper(theForm.userid.value) == false) {
alert("Please enter a valid User Name.");
theForm.userid.focus();
return false;
}

if(theForm.userid.value.length > 20) {
alert("Maximum 20 characters allowed for 'First Name'.")
theForm.userid.focus() ;
return false;
}

if(theForm.password.value==""){
//Please enter accountholder
alert("Enter the password.");
theForm.password.focus();
return false;
}

if (isProper(theForm.password.value) == false) {
alert("Please enter a valid password.");
theForm.password.focus();
return false;
}

if(theForm.password.value.length > 20) {
alert("Maximum 20 characters allowed for 'Password'.")
theForm.password.focus() ;
return false;
}

return true;
}
</script>
</head>
<body>
<H1>Admin login Page</H1>
<form method="POST" action="adminPageAction.jsp" onsubmit="return validateForm(this);">

<table border="1" ALIGN="LEFT" cellspacing="0" cellpadding="0" width="50">
<tr>
<td width="25%"><b>User-Id:</b></td>
<td width="25%">
<input type="text" name="userid" size="20">
</td>
</tr>
<tr>
<td width="25%"><b>Password:</b></td>
<td width="25%">
<input type="password" name="password" size="20">
</td>
</tr>
<tr>
<td>&nbsp</td>
<td>
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>

5)adminPageAction.jsp

<%@ page language="java" import="java.sql.*,java.io.UnsupportedEncodingException,java.security.MessageDigest,sun.misc.BASE64Encoder,sun.misc.CharacterEncoder,java.security.MessageDigest" %>


<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
Statement st = con.createStatement();
String userid=request.getParameter("userid");
String password=request.getParameter("password");

MessageDigest d = MessageDigest.getInstance("SHA");
d.update(password.getBytes("UTF-8"));
byte raw[] = d.digest();
String hash = (new BASE64Encoder()).encode(raw);
System.out.println(hash);

con.close();
out.println("Successfully");
}
catch (SQLException s){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}

%>









Related Tutorials/Questions & Answers:
lOGIN according to der roles
lOGIN according to der roles  how to login a user according to roles...(); ResultSet rs=st.executeQuery("select * from login where username='"+user...: <html> <title>Admin login Page</title> <head> <
User LogIn According to Role
User LogIn According to Role  User login According to role but output will be always displayed in a single page.. but content will change according role
Advertisements
login
login  How to create login page in jsp
login
login  How to create login page in jsp
login
login  login page display an error showing failure to login even when the correct information is entered
login
login  how to login admin and user with the same fields(name & password) in single login page while the table for admin and user is seprate in database(mysql) please provide me solution
login
login  i want to now how i can write code for form login incolude user and password in Jcreator 4.50   Hello Friend, Visit Here Thanks
login
java.awt.event.*; class Login { JButton SUBMIT; JLabel label1,label2; final JTextField text1,text2; Login() { final JFrame f=new JFrame("Login Form...(); ResultSet rs=st.executeQuery("select * from login where username='"+value1
login
login  how to create login page in jsp   Here is a jsp code that creates the login page and check whether the user is valid or not. 1...;tr><td></td><td><input type="submit" value="Login">
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
user log in according to their role
user log in according to their role  i want a jsp code for different users log in to different pages according to their role.example normal user and administrator. normal user for user page and administrator for admin page
user log in according to their role
user log in according to their role  i want a jsp code for different users log in to different pages according to their role.example normal user and administrator. normal user for user page and administrator for admin page
DIFFERENT PAGES FOR DIFFERENT USERS ACCORDING TO THEIR ROLE
DIFFERENT PAGES FOR DIFFERENT USERS ACCORDING TO THEIR ROLE  I HAVE A PROBLEM IN PHP CODING PLS HELP ME PROBLEM IS THAT I WANT DIFFERENT PAGES TO VIEW FOR DIFFERENT USERS WHEN THEY LOGIN ACCORDING TO THEIR ROLE IN DATABASE
change color according to the database value
change color according to the database value  any one know how to get values from database ( 1 or 0 ) and according to that change the color ( red or green) of given list
Match EJB roles with the corresponding description of the role's responsibilities, where the description may include deployment descriptor information.
  Match EJB roles.... EJB Overview Next     Match EJB roles... roles defined : Bean Provider The Bean
Arrange strings according to their length
Arrange strings according to their length In this section, you will learn how to arrange the strings according to their length in ascending order. For this, user is allowed to enter three strings according to their choice. The method
Change language according to the locale
Change language according to the locale  ... language according to the locale. In the code given below we have changed language according to the locale. Methods used in this example are described below
login page
login page  code for login page
login-logout
login-logout  how to do login and logout using session in php
Login page
Login page  how to create Login page in java
login page
login page  How to login as different user in php
LOGIN ERROR
LOGIN ERROR  ERROR SCRIPT: LOGIN FAILED", $_SESSION['login fail']='0',}?> Ty Team
Login authentication
Login authentication  i want d code for login authentication from mysql database on the same pc using swings
Login authentication
Login authentication  i want d code for login authentication from mysql database on the same pc using swings
Login Page
Login Page  Can anyone tell me the steps to create a login page in myeclipse 7.0 and validating it with login database in db2 9.7 ??? Please tell me
LOGIN PAGE
LOGIN PAGE  A java program with "login" as title,menus added, and a text field asking for firstname, lastname, and displaying current date and time
login application
login application  how to create login application ?   Hi, Please check the following tutorials: Video tutorial - JSP Login Logout Example Login Authentication using Bean and Servlet In JSP simple code to login user
Login Program
Login Program  Login program in struts to set username & password in session. and this session is available in all screens for authentication..., Please read it at: Login/Logout With Session Accessing Session Object Thanks
Tutorials   
Java Spring Hibernate Struts Training fat image from db fat image from db fat image from db fat image from db unable to get value returned from javascript variable in page How to change image size before adding to mysql using jsp Design a registration.jsp page with input for user registration details Cart Quantity jsp servlet coding issue servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? image pdf marking pdf marking Multiple image upload using JSP Read code from excel sheet and upload into database using JSP Student java about search engine Convert BLOB to PDF and save it to a location how to copy files from remote to local machine using SFTP SSL in java? Like Team viewer Socket and Servert -Jsp how to copy files from remote location to local using java? How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java how to create SOAP based web service in java? how to fetch data from mysql database table and draw a bar chart on that data using in jsp how to create users in LDAP using java? how to authenticate user using TIVOLI api in java? how to create users using IBM Tivoi API in jsp/servelet? Java/J2ee Please explain this code as many packages and classes are unknown to me .! how to download the uploaded folder files using jsp Login Query image is display from path of mysql database please reply the code to store dynamic fields in database? Reloading issue in jsp How to get Button Id ? calling one jap page from another jsp page login login Problem to get connection from DAO class to JDBC Page Loading Time Fix table's column's name row(1st row of the table) so that it does not move up when the table is scrolled up to view more rows below Sending hidden values

Ads

 
Advertisement null

Ads