Monday, 6 May 2013

Code for forgot password module using JSP and Servlet

code for forgot password

Following directory Structure you need to create for this(Tomcat directory i had used)

WEB.xml

JSP files

  • ResetPassword.jsp
  • SetNewPassword.jsp

CSS File

  • tableLayout.css

Servlet

  • AuthenticateRequest.java
  • ResetPassword.java
  • SendResetLink.java

Common Classes

  • AESEncryption.java
  • Base64Coder.java
  • Datedifference.java
  • DBconnection.java
  • SendMail.java

DAO

  • FPDao.java

Utility Class

  • Utility.java

Properties files

  • DB.properties
  • mail-config.properties
To get full code just click on the link
click to get
Please give your feedback by giving comments

26 comments:

  1. goood work bro...!! Keep it going..>!!

    ReplyDelete
  2. Dear Gaurav,

    Thanx for sharing a valueable code...
    i hv a little prblm wid my Task manager...its nt enable in my lappy...if u hv knowledge abt it...so plz share wid me..

    Abhishek

    ReplyDelete
  3. @abhishek: i think it might be because of viruses in your system.
    Once u chk registry editor, n chk or locate "disabletaskmgr".
    U hav to ckh fr dword value . Change it to '0' or create a new value, if its nt there.
    Restart ur system once.
    I think it will work.

    Gaurav

    ReplyDelete
    Replies
    1. Thanx a lot....i hope it work...
      @Gaurav

      Delete
  4. I am enable to download Code... I have given Request Access (permission) for downloading.. Help me to download it.

    ReplyDelete
    Replies
    1. hi Mangesh Mandavgane
      U can download the code directly from the blog now.

      Delete
  5. i am working with your forgot password code, but its giving me internal error occured, please try later, reason = null, i am a beginer could you help me to fix it

    ReplyDelete
    Replies
    1. Hi neelakandan apologies for the late reply..

      I think you are not setting database property properly and getting null pointers from FPDao.
      So once you go to com.fpwd.commonconfig.DB.properties file and provide a valid db url.

      Also for better understanding you can write logs for the project.

      Also set a valid "forgetpasswordlink" and "redirectUrl" into DB.properties file.

      forgetpasswordlink= This is the link that will be send into mail id for resetting the password.

      Use the below link to download the code

      https://drive.google.com/open?id=0B-8DMZISwXbPeW5SZkZjdGxkb1E

      Delete
  6. I am getting an error :-

    Reason:-Can't find bundle for base name /DB.properties, locale en_GB.

    Please help to resolve.

    ReplyDelete
    Replies
    1. hi anurag,
      Make sure that your DB.properties file must be present in the below dir.
      com.fpwd.commonconfig.DB.properties file.

      You can download the code from the blog for better understanding.

      Delete
  7. I am getting an error :- Reason:Null

    ReplyDelete
  8. hi guys apologies for the late reply..
    you can download the whole code from link mentioned in the my blog (click here to get link) at the end.
    Make sure of changing Db urls and mail properties.Configure them properly as per your details.
    The code is written to send and validate your password link based on these inputs.
    For better understanding I encouraged all to write logs or sout statement to see code flow.
    Thank you for showing your interest and your valuable feedback.

    ReplyDelete
  9. thanks for the post gaurav,but the authenticate java class is giving a null pointer ,how to fix it ,got stuck with this code

    ReplyDelete
    Replies
    1. if your getting null pointer from authenticateRequest.java then you once check verifyRequest method of FPDao.
      This method will verify the utid and email with database once you clicked on the reset link in mail
      Just keep some log in this method to check it.
      See In case of any exception dataMap will return "RESULT", "EXCEPTION" as exception and "REASON", e.getMessage() and controller will display corresponding message based on this.
      I think your getting from this place only.

      Delete
  10. Yes Gaurav I have fixed the error.There was a space coming in the link on the respective mail id and hence the value was not getting returned to the jsp.I have removed the space in the link and the rest of the code is working fine.
    Thank you for the great post Gaurav. In case I need any further help will definitely contact you.

    Regards,
    Saptarshi

    ReplyDelete
  11. gaurav, a new problem has arrived again, The code was working fine ,but it is not accepting a new gmail id and password.
    Every time it is giving a error of javax mail.authenticatin error , username and password are not accepted .
    it was working fine until i chnaged my password for the gmail account and now its throwing the same error.how to fix it ???

    neeed help from you

    ReplyDelete
  12. gaurav, a new problem has arrived again, The code was working fine ,but it is not accepting a new gmail id and password.
    Every time it is giving a error of javax mail.authenticatin error , username and password are not accepted .
    it was working fine until i chnaged my password for the gmail account and now its throwing the same error.how to fix it ???

    neeed help from you

    ReplyDelete
  13. hi Gaurav i need to know the overall db structure and scenerio how the coding works , I am a fresher in IT Industry...Can u Revert back to my mail shannushyl@gmail.com

    ReplyDelete
  14. Hi Gaurav,
    I am getting following exception
    the transport.connect() method throws exception
    com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;

    ReplyDelete
  15. ==================================================================================
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.port", port);
    props.put("mail.smtp.username", mail_from);
    props.put("mail.smtp.password", mail_pwd);
    props.put("mail.smtp.auth", authtype);
    props.put("mail.smtp.debug", "true");
    props.put("mail.transport.protocol", "smtp");
    /* props.put("mail.smtp.starttls.enable","false"); // if it is true then it enabling SSL on this connection
    props.put("mail.smtp.socketFactory.port", port);
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.socketFactory.fallback", "false"); //false
    */

    Session session = Session.getInstance(prop, new Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(mail_from,mail_pwd);
    }
    });
    ==============================================================================

    // send the message
    int intport=Integer.parseInt(port);
    Transport transport = session.getTransport("smtp");
    transport.connect(host, intport, mail_from, mail_pwd);
    Transport.send(msg); // This line throws Exception
    System.out.println("Mail Send sucessfully");
    ==================================================================================

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. Hello sir, when i am working with your forgot password code, but its giving me internal Exception occured, please try later, reason = null, i am a beginer could you help me to fix it.

    ReplyDelete
  18. hello sir,im trying to run your sample project but "encounted error Internal Exception Occured! Please try Later
    Reason:-null", i already set up to all configuration but have error.

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. hello sir,im trying to run your sample project but "encounted error Internal Exception Occured! Please try Later
    Reason:-null", i already set up to all configuration but have error.

    ReplyDelete