2

i have connected my login.jsp and registration.jsp to my database, signup is successful but when i login i get error message "password invalid" i think my code has a problem, please can someone help me solve that, the code is found below . Thanks in advance.

login.jsp

<%@ page import ="java.sql.*" %>
<%
    String userid = request.getParameter("uname");
    String email = request.getParameter("emailsignup");
    String password = request.getParameter("password");
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = 
DriverManager.getConnection("jdbc:mysql://localhost:3306/mldn","root","shaddy");
    Statement st = con.createStatement();
    ResultSet rs;
    rs = st.executeQuery("select * from members WHERE uname='" + userid + "' and password='" + password +"'");
    if (rs.next()) {
        session.setAttribute("userid", userid);
        out.println("welcome " + userid);
        out.println("<a href='logout.jsp'>Log out</a>");
        response.sendRedirect("<a href='index.jsp'>Welcome</a>");
     } else {
        out.println("Invalid password <a href='index.jsp'>try again</a>");
    }
%> 

HTML

<header>
                <h1>Geo Business/Land inventory<br><span>Login And Registration</span></h1>
            </header>
            <section>               
                <div id="container_demo" >
                    <a class="hiddenanchor" id="toregister"></a>
                    <a class="hiddenanchor" id="tologin"></a>
                    <div id="wrapper">
                        <div id="login" class="animate form">
                            <form  action = 'jsp/login.jsp'> 
                                <h1>Log in</h1> 
                                <p> 
                                    <label for="username" class="uname" data-icon="u" > Your Username </label>
                                    <input id="username" name="username"  required="required" type="text" placeholder="myusername." value=""/>
                                </p>
                                <p> 
                                    <label for="password" class="youpasswd" data-icon="p"> Your password </label>
                                    <input id="password" name="password"  required="required" type="password" placeholder=" X8df!90EO" value=""/> 
                                </p>
                                <p class="keeplogin"> 
                                    <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" /> 
                                    <label for="loginkeeping">Keep me logged in</label>
                                </p>
                                <p class="login button"> 
                                    <input type="submit" value="Login" /> 
                                </p>
                                <p class="change_link">
                                    Not a member yet ?
                                    <a href="#toregister" class="to_register">Join us</a>
                                </p>
                            </form>
                        </div>

                        <div id="register" class="animate form">
                            <form  action = 'jsp/registration.jsp'> 
                                <h1> Sign up </h1> 
                                <p> 
                                    <label for="fname" class="fname" data-icon="fn">First Name</label>
                                    <input id="fname" name="fname" required="required" type="text" placeholder="myfirstname" value=""/>
                                </p>
                                <p> 
                                    <label for="lname" class="lname" data-icon="ln" >Last Name</label>
                                    <input id="lname" name="lname" required="required" type="text" placeholder="lastname" value=""/> 
                                </p>
                                <p> 
                                    <label for="email" class="emailsignup" data-icon="e" >Email</label>
                                    <input id="email" name="email" required="required" type="email" placeholder="[email protected]" value=""/> 
                                </p
                                <p> 
                                    <label for="username" class="uname" data-icon="u">Username </label>
                                    <input id="username" name="username" required="required" type="username" placeholder="eg. X8df!90EO" value=""/>
                                </p>
                                <p> 
                                    <label for="password" class="youpasswd" data-icon="p">Password </label>
                                    <input id="password" name="password" required="required" type="password" placeholder=" eg.X8df!90EO" value="" />
                                </p>
                                <p class="signin button"> 
                                    <input type="submit" value="Sign up"/>
                                </p>
                                <p class="change_link">  
                                    Already a member ?
                                    <a href="#tologin" class="to_register"> Go and log in </a>
                                </p>
                            </form>
                        </div>

                    </div>
                </div>  
            </section>
        </div>
    </body>
</html>
2
  • kindly use taglibs instead of scriptlets if possible, use PreparedStatement istead of Statement, also whats the column type of password in table? Here spaces might be an issue. Commented Oct 14, 2014 at 5:03
  • please post your html Commented Oct 14, 2014 at 5:10

2 Answers 2

3

You need to make sure that the Username and Password you requesting from your html form is correct.

The request.getParameter method returns the value of the input form field which have the same name given inside the parenthesis.

For example:

html:

<form action="/action.jsp">
<input type="text" value="text" name="input1">
<input type="submit" value="submit">
</form>

action.jsp:

String text=request.getParameter("input1");//will return the value 'text'

Please try printing the value in jsp and make sure the values are intact

Sign up to request clarification or add additional context in comments.

10 Comments

,Thanks for your respond here is my HTML. its too log
its too long to upload but i will try to do that in parts ASAP. THNKS
<h1>Log in</h1> <p> <label for="username" class="uname" data-icon="u" > Your email or username </label> <input id="username" name="username" required="required" type="text" placeholder="myusername or [email protected]" value=""/>
<p> <label for="password" class="youpasswd" data-icon="p"> Your password </label> <input id="password" name="password" required="required" type="password" placeholder=" X8df!90EO" value=""/> </p>
</p> <p class="keeplogin"> <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" /> <label for="loginkeeping">Keep me logged in</label> </p> <p class="login button"> <input type="submit" value="Login" /> </p> <p class="change_link"> Not a member yet ? <a href="#toregister" class="to_register">Join us</a> </p> </form>
|
0

I was making the same mistake, in HTML part the input type tag should have a name attribute which can be the used by getParameter Method to get the input from the user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.