• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Forgot Password returns null mail while entering in the textarea.

 
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gayathri Gayu wrote:Means?



Is this servlet called when the user clicks on the reset link in his/her email?
 
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. So I should add some code in my sendmail.java file? or I should call like ?
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Else do I need to add in my web.xml?
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gayathri Gayu wrote:No. So I should add some code in my sendmail.java file? or I should call like ?



So when is it called?
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I tried adding the line in SendMail.java file It is throwing the following error

Server Tomcat v8.5 Server at localhost failed to start.


 
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WebServlet annotation can't be in that class.  It's part of servlet, and you didn't answer my question.  When is the PasswordResetServlet called?  When the user clicks on resetpassword option?
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's called in jsp page only when the user submit the form
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the functionality if this servlet should be to generate the tokenid,send the mail and save the details in the table.  You seem to have already done that.  Now, when the user clicks on reset link in his/her email you should have another servlet e.g PassowrdUpdateServlet that will retrieve the token id and perform other functionalities.  So the path you are sending through email should look somewhat like this.



and in PassowrdUpdateServlet you retrieve the tokenid



and don't forget to add PasswordUpdateServlet in web.xml.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you told I changed the path .  I have created another servlet named PasswordUpdateServlet. with same code of PasswordResetServlet's
Here I tried to retrieve the tokenid alone. When I tried to add in PasswordResetServlet file It is throwing the server error.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show the code of PasswordDAO and registerbean.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PasswordDao code

RegisterBean
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//servlet code




 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have added the servlet code and add the tokenid in ForgotPasswordBean and along with existing code added the following code in PasswordDao. But it is not working. Till the database entry is happening.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gayathri Gayu wrote:I have added the servlet code and add the tokenid in ForgotPasswordBean and along with existing code added the following code in PasswordDao. But it is not working. Till the database entry is happening.



What do you mean by not working?  Do you get the link in mail?  If yes what happens when you click on that link?
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I got the link in my mail.

Unable to connect
Firefox can’t establish a connection to the server at localhost.

   The site could be temporarily unavailable or too busy. Try again in a few moments.
   If you are unable to load any pages, check your computer’s network connection.
   If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.


When I tried to access the link I got the above error.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you run the first page from eclipse how does the url look like in the browser?  Just copy and paste the url here.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show web.xml, by first page do you mean index.html/index.jsp?
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Index.html code
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change the path in sendmail as follows

Change the following


to



and see if it helps
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes now its giving me different error.

HTTP Status 405 – Method Not Allowed
Type Status Report
Message HTTP method GET is not supported by this URL
Description The method received in the request-line is known by the origin server but not supported by the target resource.

 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show complete code not just part of PasswordUpdateServlet.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
code of passwordupdateservlet
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change doPost to doGet



to

 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code works now. But instead of

if

its printing the else statement.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println(tokenId);  Does it show the tokenId in PasswordUpdateSevlet?
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes the tokenId is printing at passwordupdateservlet, But at PasswordDao.java its returning null.

 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change the method authenticateUserByTokenId like this



and in PasswordUpdateServlet

 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That works. Thanks for the help. How will i set the expire time. Do i need to add a column in the database?
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.  In userpwd table.  Say the column name is TIMESTAMP.  When you are saving the record here, save the current time in millis.  When the request comes for reset to PasswordUpdateServlet, while validating the tokenid retrieve the savedtimestamp and compare with current time stamp, if it passes the allowed time show some error like link already expired.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Created the table with following fields.
I have to retrieve the time stamp like as you said. Also I have to add TIMESTAMP property in ForgotPasswordBean.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your logic should be somewhat lke this








//KEEP BACKUP OF EXISTING CODE AS IT WORKED FINE.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the time of creating table for registration i have to specify the time stamp right. Then only it will check with both the time.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I am keeping the filed name is TIMESTAMP but suggesting you to keep the data type as BIGINT, where you can save a long value in millisecond format, for easier comparison when you compare when reset request is received.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The passworddao code
 authenticateUserByTokenId(String tokenId) asks for return statement. So I added return 0 at last. ResultSet c = null; I added as the return statement throws error for creating variable/field/constant. Its printing the helooooooooooooo and then 0. Its not returning return c.getLong(1);

Its printing the tokenId. and entering into the else case giving the link failure message.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its not entering in the if


I tried printing and got the output as HEllo26257406 link failed
 
Master Rancher
Posts: 4371
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, the time stored looks like millis, not minutes, so currently your token is valid for 5 milliseconds.

Second, that query on line 16 is prone to SQL injection, especially since tokenId is coming in from outside the application.
That needs to be changed to a PreparedStatement.

Thirdly, you are eating that exception.  You need to, at the very least, print the stack trace.
You also need to figure out what to do if you do get an exception (which probably means the database is not working properly).
At the moment you are automatically letting the user change their password (assuming you are using the same code Swastik posted) as you return 0, and the calling code only checks for -1.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was showing error to keep return statement so i kept return. Wat else value should i keep in the return statement?
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The saved time is 0.  As i kept   in passwordDao.Please tell me what should i change now?
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this once

 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!