Home > Back-end >  Logon authentications bypass the problem about how to prevent
Logon authentications bypass the problem about how to prevent

Time:10-20

Site has three log files, respectively is the login. The JSP, check_login. JSP, login_success. JSP account and password authentication through jump login_success. JSP.
The question now is, in fact, if the user knows the login_success. JSP, you can directly address access, said through the session mechanism on the net, I want to ask, how to code in my example,
Login. JSP code below
 & lt; % @ page language="Java" contentType="text/HTML. Charset=utf-8 "
PageEncoding="utf-8" % & gt;



<meta charset="utf-8" & gt;
Login case & lt;/title> <br/><link rel="stylesheet" <br/>Href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" <br/>Integrity="sha384 BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va + PmSTsz/K68vbdEjh4u" <br/>Crossorigin="anonymous" & gt; <br/></head> <br/><body> <br/><Div & gt; <br/><Div style="margin - top: 30 px" & gt; <br/><Div & gt; <br/><Div & gt; <br/><Div & gt; <br/><Span & gt; </span> Login <br/></div> <br/><Div & gt; <br/><The form action="check_login. JSP method=" POST "" name=" loginForm & gt;" <br/><Div & gt; <br/><The label for="name" & gt; The user name & lt;/label> <Input type="text" <br/>Name="name" placeholder="please enter the user name" & gt; <br/></div> <br/><Div & gt; <br/><The label for="" & gt; Password & lt;/label> <Input type="password" <br/>Name="PWD" placeholder="please enter the password" & gt; <br/></div> <br/><The button type="submit" <br/>"Onclick=" return checkForm () & gt; Login & lt;/button> <br/></form> <br/></div> <br/></div> <br/></div> <br/></div> <br/></div> <br/></body> <br/><script <br/>SRC="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" <br/>Integrity="sha384 - Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" <br/>Crossorigin="anonymous" & gt; <br/><br/></script> <br/><script type="text/javascript"> <br/>The function checkForm () {<br/>Var name=loginForm. Name. The value; <br/>Value; var PWD=loginForm. PWD. <br/>//alert (name + PWD); <br/>If (name=="" | | name==null) {<br/>Alert (" please enter the user name "); <br/>LoginForm. Name. Focus (); <br/>return false; <br/>} else if (PWD=="" | | PWD==null) {<br/>Alert (" please enter the password "); <br/>LoginForm. PWD. Focus (); <br/>return false; <br/>} <br/>return true; <br/>} <br/></script> <br/></html> </pre> <br/>Check_login. JSP code to the <pre> & lt; % @ page import="Java. SQL. *" % & gt; <br/><% @ page language="Java" contentType="text/HTML. Charset=utf-8 "<br/>PageEncoding="utf-8" % & gt; <br/><% <br/>Connection conn=null; <br/>PreparedStatement ps=null; <br/>ResultSet rs=null; <br/>Class.forname (". Com. Mysql. Cj. JDBC Driver "); <br/>The String url="JDBC: mysql://localhost: 3306/testapp? UseSSL=false& ServerTimezone=UTC& UseUnicode=true& CharacterEncoding=utf-8 "; <br/>String username="root"; <br/>String password="123456"; <br/>Conn=DriverManager. GetConnection (url, username, password); <br/>request.setCharacterEncoding("utf-8"); <br/>String name=request. The getParameter (" name "); <br/>String PWD=request. The getParameter (" PWD "); <br/>String SQL="SELECT * FROM the userinfo WHERE user='" + name +"' AND password='" + PWD + "' "; <br/>Ps=conn. PrepareStatement (SQL); <br/>Rs=ps. ExecuteQuery (); <br/>{if (rs. Next ()) <br/>The response. SendRedirect ("./login_success. JSP "); <br/>} else {<br/>The response. SendRedirect ("./login. JSP "); <br/>} <br/>% & gt; </pre> <br/>Login_success. JSP code is <pre> & lt; % @ page language="Java" contentType="text/HTML. Charset=utf-8 "<br/>PageEncoding="utf-8" % & gt; <br/><! DOCTYPE html> <br/><html> <br/><head> <br/><meta charset="utf-8"> <br/><title> Sunset twilight & lt;/title> <br/></head> <br/><body> <br/><br/><A href="https://bbs.csdn.net/topics/movie/index.html" target="_blank" & gt; Movie</a> <br/><br/><p> </p> <br/><A href="https://bbs.csdn.net/topics/jpg/index.html" target="_blank" & gt; Jpg</a> <br/><br/><p> </p> <br/><A href="https://bbs.csdn.net/topics/txt/index.html" target="_blank" & gt; Txt</a> <br/><br/><p> </p> <br/><br/></body> <br/></html> </pre><p class="article - content rp"> CodePudding user response: </p>Explain, I have not learned Java or scrip, Java programming, learned some of the c language, according to the experience changes to the code online, but online about the use of the session, only use part of its context is not clear, so a great god, please help to give directions, in my example how to realize the function of preventing bypass the login authentication,<p class="article - content rp"> CodePudding user response: </p>Filters, pass the login. The JSP, check - login. JSP, check - login. JSPS, after a successful login session record whether is logged in, all other requests need to verify whether tags in the session is logged in, login not redirected to the loin. JSP is logged in<p class="article - content rp"> CodePudding user response: </p><fieldset> <legend> refer to the second floor dkwuxiang response: <legend> <blockquote> filter, pass the login. The JSP, check - login. JSP, check - login. JSPS, after a successful login session record whether is logged in, all other requests need to verify whether tags in the session is logged in, login not redirected to the loin. JSP, logged-in release </blockquote> <fieldset> <br/>Theory is the online check, even code, but the code are not instances of application, or I don't know how in the instance, hope to have friends to specific how to achieve in my example, <br/>In addition to increase the content of the session in the database, if necessary, I can control increase in mysql<p class="article - content rp"> CodePudding user response: </p>You can configure a blocker Interceptors<p class="article - content rp"> CodePudding user response: </p>The actual architectural complex, far more than you think can use a variety of framework, and basic will not have direct access to the JSP, all requests are first servlet/controller/action again jump. <br/><br/>Check whether the login, filters can be done, how to maintain the session, that depends on what you used in solution, broadly similar.nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/Backend/69123.html" target="_blank" style="color:#999">https//www.codepudding.com/Backend/69123.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/Backend/69122.html'>How to make!</a></div> <div class="detail-arr-right">Next:<a href='/Backend/69124.html'>ArrayList <Object></a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=Web+development' target='_blank'>Web development</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>