STIW2024 / Main-Issues

2 stars 0 forks source link

Login Page #5

Open zhamri opened 7 years ago

zhamri commented 7 years ago

All students must create a new branch using "metric number" in your team repo.

Create a login page (login.jsp). If the user_name and password are correct, then display HelloWorld.jsp (Issue #1 )

Then upload login.jsp and HelloWorld.jsp to the new branch.

JohnWick27 commented 7 years ago

Login Page

loginpage

HelloWorld Page

hellow

Database

datbeas

kzkit commented 7 years ago

Index :

`<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Login</title>
</head>

<body>
<h1 align="center"> LOGIN FORM  </h1>
<form  METHOD=GET ACTION="login.jsp">
    Username : <input type="text" name="uname">
    Password : <input type="password"  name="passwd">
    <input type="submit" value="LOGIN">
</form>
</body>
</html>`

Login

<!DOCTYPE html>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.*,javax.servlet.http.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<html lang="en">
<head>

  <title>Welcome</title>
</head>

<body>
      <sql:setDataSource 
        var="usr"
            url="jdbc:mysql://localhost:3306/login"
            driver="com.mysql.jdbc.Driver"
            user="root" password="" 
        />
        <sql:query dataSource="${usr}" var="result1" >
                select * from login where name=? 
                <sql:param value="${param.name}"/>
        </sql:query>

        <c:forEach var="row1" items="${result1.rows}">
            <c:set var="flag1" scope="application" value="1"/>
        </c:forEach>

        <sql:query dataSource="${usr}" var="result2" >
            select * from login where name=? and password=?
            <sql:param value="${param.uname}"/>
            <sql:param value="${param.passwd}"/>
        </sql:query>

        <c:forEach var="row2" items="${result2.rows}">
        <c:set var="flag2" scope="application" value="1"/>
        </c:forEach>

            <c:choose>
            <c:when test="${flag2 eq 1}">
            <c:forEach var="row2" items="${result2.rows}">
            <c:set var="flag2" scope="application" value="1"/>

                <h1>
                    Correct <c:out value="${row2.uname}"/>

            </c:forEach>
                <c:set var="flag1" scope="application" value="0"/>
                <c:set var="flag2" scope="application" value="0"/>

            </c:when>

            <c:when test="${flag1 eq 0}">

                <h1>
                    User Not Registered
                </h1>

                <c:set var="user_flag" scope="application" value="0"/>
                <c:set var="flag" scope="application" value="0"/>
            </c:when>

            <c:otherwise>

                <h1>
                    Invalid Password , Try Again !!!
                </h1>

                <c:set var="user_flag" scope="application" value="0"/>
                <c:set var="flag" scope="application" value="0"/>
            </c:otherwise>
            </c:choose>
        <jsp:forward page = "helloworld.jsp" />
</body>
</html>

Hello World

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <font size="10" color="red"><%="Hello World" %></font>
        <br>
        <font size="20" color="blue"><%="STIW2024 Software Engineering" %></font>
        <body bgcolor="pink">

    </body>
</html>

login login2 databaselogin

jairam0905 commented 7 years ago

1 2 3 4 5 6

Reference. https://www.youtube.com/watch?v=MKVOiYLCzA8

thiviya commented 7 years ago

index <%@ page import="java.sql.*" %>

Login page <% Connection con= null; PreparedStatement ps = null; ResultSet rs = null; String sql = "select password from userdetail"; try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/logindb", "root", ""); ps = con.prepareStatement(sql); rs = ps.executeQuery(); %>

login page

<% } catch(SQLException sqe) { out.println("home"+sqe); } %>
Enter Your Name :
Enter Your Password :

login <%@ page import="java.sql.*" %>

Login <%! String userdbName; String userdbPsw; %> <% Connection con= null; PreparedStatement ps = null; ResultSet rs = null; String sql = "select * from userdetail where name=? and password=?"; String name = request.getParameter("name"); String password = request.getParameter("password"); if((!(name.equals(null) || name.equals("")) && !(password.equals(null) || password.equals("")))) { try{ Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/logindb", "root", ""); ps = con.prepareStatement(sql); ps.setString(1, name); ps.setString(2, password); rs = ps.executeQuery(); if(rs.next()) { userdbName = rs.getString("name"); userdbPsw = rs.getString("password"); if(name.equals(userdbName) && password.equals(userdbPsw)) { session.setAttribute("name",userdbName); response.sendRedirect("HelloWorld.jsp"); } } else rs.close(); ps.close(); } catch(SQLException sqe) { out.println(sqe); } } else { %>

Error In Login

<% getServletContext().getRequestDispatcher("/index.jsp").include(request, response); } %>

HelloWorld

Welcome

Hello World!

STIW2024 Software Engineering

output image image image image

Reference https://www.roseindia.net/jsp/jsp-login-form-with-mysql-database-connection-and-back-end-validation.shtml

nadiahnaz commented 7 years ago

database login_web_browser helloworld_web_browser login verify_01 verify_02 helloworld

yaopeng96 commented 7 years ago

loginpg loginpg1 login1 login2 welcome login hello

NgZhengYi commented 7 years ago

Login.jsp

image

Verify.jsp

image image

Output

image image

Reference

http://www.lionblogger.com/simple-jsp-login-page-with-mysql/

ezzat787 commented 7 years ago

1111 2222 3333 55555 66666 7777 8888 9999 1000

najihah2104 commented 7 years ago

login1 login2 login3 login4 login5

najihah2104 commented 7 years ago

reference: https://www.youtube.com/watch?v=CeGDp0Rym5g

ChoyCheeWei commented 7 years ago

1 2 3 4 5 6 reference: https://www.youtube.com/watch?v=MKVOiYLCzA8

kopilim96 commented 7 years ago

1st --> index.html image 2nd --> loginto.jsp image 3rd --> helloworld.jsp image With correct password image image with Wrong password image

Koksheng commented 7 years ago

1 2 3 4 5 db

yeepheng96 commented 7 years ago

Login.jsp screenshot 2017-11-28 01 46 45 Verify.jsp screenshot 2017-11-28 01 51 11 screenshot 2017-11-28 01 51 17 HelloWorld.jsp screenshot 2017-11-28 01 47 11 login database (MYSQL) screenshot 2017-11-28 01 47 17 Output screenshot 2017-11-28 01 47 30 screenshot 2017-11-28 01 47 39 Reference: http://www.lionblogger.com/simple-jsp-login-page-with-mysql/

afiqznw commented 7 years ago

1 2 3 4 5

ariffafif commented 7 years ago

image

image

image

image

image

image

image

YangYifei666 commented 7 years ago

image image image

AiniArasad commented 7 years ago

image

image

image

image

image

image

Reference : https://www.youtube.com/watch?v=MKVOiYLCzA8

LoiTongFong commented 7 years ago

issue 5 7 issue5 6 issue5 5 isssue5 1 issue5 2 issue 5 3 issue 5 4

Reference: https://www.youtube.com/watch?v=MKVOiYLCzA8

Nadzifa707 commented 7 years ago

image

image

image

image

image

image

REFERENCE : https://www.youtube.com/watch?v=MKVOiYLCzA8

Aman748 commented 7 years ago

Page code (only jsp) :

<%-- 
    Document   : login
    Created on : 2017-11-28, 3:07:31
    Author     : Aman
--%>

<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Login</title>
    </head>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
        <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
        <link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet'>
        <link href="./css/Loginbox.css" rel="stylesheet">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/jquery.validate.min.js"></script> 
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <body>
        <div class="text-center" style="padding:12% 0">
            <div class="logo">Login</div>
            <div class="login-form-1">
                <form id="login-form" class="text-left">
                    <div class="login-form-main-message"></div>
                    <div class="main-login-form">
                        <div class="login-group">
                            <div class="form-group">
                                <label for="lg_username" class="sr-only">Username</label>
                                <input type="text" class="form-control input-lg" id="lg_username" name="lg_username" placeholder="username">
                            </div>
                            <div class="form-group">
                                <label for="lg_password" class="sr-only">Password</label>
                                <input type="password" class="form-control input-lg" id="lg_password" name="lg_password" placeholder="password">
                            </div>
                            <div class="form-group login-group-checkbox">
                                <input type="checkbox" id="lg_remember" name="lg_remember">
                                <label for="lg_remember">remember</label>
                            </div>
                        </div>
                        <button type="submit" id="check" class="login-button"><i class="fa fa-chevron-right"></i></button>
                    </div>
                </form>
            </div>
        </div>
        <%
        try{
            String username = request.getParameter("lg_username");   
            String password = request.getParameter("lg_password");
            Class.forName("com.mysql.jdbc.Driver");  // MySQL database connection
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/SoftwareEngineering","root","****" );    
            PreparedStatement pst = conn.prepareStatement("Select Username,Password from login where Username=? and Password=?");
            pst.setString(1, username);
            pst.setString(2, password);
            ResultSet rs = pst.executeQuery();
            if(rs.next()){
            %>
            <jsp:forward page="index.jsp"/>
            <%
            }
        }
        catch(Exception e){             
        }
        %>
        <script src="./js/Loginbox.js" type="text/javascript"></script>
    </body>
</html>

GIF :

1

Screenshot :

2017-11-29 11 06 15

Lilinhong123 commented 7 years ago

11 22 33 44 55 66 77

NurSyahirah1296 commented 6 years ago

screenshot_6 screenshot_7 screenshot_8 screenshot_9 screenshot_10