• 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.

 
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have three features in my form for register,login,forgot password. The following code is the forgot password bean.



Following code is forgot password dao.



When I tried printing the email which is entered in textbox it returns null value. I don't know where I am wrong. Please help me.
 
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the servlet code of ForgotPassword.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posting the servlet code for your reference.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you getting null in the following line

 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the htm/jsp code of forgotpassword from where you are calling this servlet.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jsp code.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The name attribute in html tag is Email, but in servlet it's email, so there is case mismatch.  Either change name attribute in html as email or in servlet change it to getParameter("Email").  It needs to be same.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help @Swastik Dey.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always welcome Gayathri,
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going through the post forgot-password



I already have my sendmail.java code for sending emails. But I don't know how to implement or add the above code in my application. Can you please help me by giving your valuable suggestions. Or any idea about generate a key (GUID)?
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying with the following code. For sending mail. But I don't know how will i link this with my web.xml. How will I generate the hash 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

Gayathri Gayu wrote: Or any idea about generate a key (GUID)?


 
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: Or any idea about generate a key (GUID)?


 
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 am trying with the following code. For sending mail. But I don't know how will i link this with my web.xml. How will I generate the hash code?

Why do you want to link with web.xml?  That's a configuration file for server.

 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:

Gayathri Gayu wrote: Or any idea about generate a key (GUID)?




I don't know how to implement that in my code. Do i need to add any columns in my database? How it will works?
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So Will this code work?



How will i

[Domain Name]/user/[user-id]/activate/[some 32 characters hash code]

give the path?
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For what purpose do you need a GUID?
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what i am trying to find. We can not give the path directly.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong in giving the path of html/jsp page directly?
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wenever they want they can access if we are giving direct path. But forgot password will give us the link with a different token and i would like to set expiration for that link. Which they can access the link for sometime only.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok..so where is your problem?
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how to implement the GUID also I don't know whether the code is right way for implementing?

 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use another table like this confirmation_tokens with following fields

confirmation_token varchar(200),email_id(or userid whatever it is),created_date datetime

The confirmation token is nothing but a GUID value.  Whenever you send the password reset link, you generate a GUID a form a link somewhat like this

http://localhost/passwordreset?tokenid=<generatedtokenid>;  and at the same time you save a record in the table I mentioned above with tokenid,emailid,and current datetime.

When the user clicks on the link you retrieve the tokenid parameter , and validate from the above table because you have already stored the record while sending the mail.

 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created the table with following fields as you told. CREATE TABLE userpwd ( confirmation_token varchar(200),Email VARCHAR(254), reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);  I understand that on the button click for reset password I have to add code for generating key generate a GUID a form a link somewhat like this . But  I don't know how I will first generate the link

http://localhost/passwordreset?tokenid=<generatedtokenid>;

and how the token id will get generated.

save a record in the table I mentioned above with tokenid,emailid,and current datetime.

Here i have to either insert or update the record.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your code of sending the mail  In which you are sending the reset link
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code for sending mail
 
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
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The password passwordresetservlet is a jav file something like registerservlet.java right? Or should i add the code for reset password in registerservlet.java file itself? Because you told earlier that there should be only one servlet class.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ideally as per MVC you should have one but for the time being create a new because you wish to handle from the same servlet you have to pass another parameter in the link,  so for the time being create a new one, and before going to that servlet part first check whether the link coming properly in email or not.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But by creating new one how will do mapping in the 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
Post the web.xml code
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
web.xml 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
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code is for password reset.



So in the above code in the if statement i need to save the record in the table you had mentioned? I am having two tables
1) Users -- While registration is happening.
2) userpwd -- for inserting/updating the password while the user clicks forgot password. Is the procedure correct?
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are  steps involved here.  

1.  When the user clicks on Password reset link/button you send him/her the mail and save the record in table I mentioned.  So this is done using one servlet.

2.  User clicks on the reset link you retrieve the tokenId and validate against the record you saved in previous step.  If it is a valid, you redirect the user to the reset page and delete the record from the table you saved in step1.  So the entire process of step2 should be done in another servlet.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So one is passwordresetservler which generate the token id and will save it in database. And one more for e.g. passwordservlet is to validate/verify whether the record matches the user record and after the validation/verification for showing the reset password fields? Is it so?
 
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, and don't hurry.  First try to proceed with emailing the link and see whether this part woks properly or not, then go to the next part.
 
Gayathri Gayu
Ranch Foreman
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Thanks for your concern. So now i have tried registering whether the user receives the mail with the token id and it works fine. So now i need to save the record in the table.

And the following code

Code in forgotpassworddao.
 
Swastik Dey
Master Rancher
Posts: 2249
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Save the record where?  This is the registration page right? So it will save in users table not in the table I mentioned.  That's for password reset.
 
He's giving us the slip! Quick! Grab 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!