Forget Password link using gwt

心不动则不痛 提交于 2019-12-12 19:35:03

问题


In my site i have a link Forgot Password when i click on this link a page will come so we fill emailId and send mail to particular gmailid(in this mail we have to generate a link). when we have click on generated link page open for reset password(like new password ar confirm password).

My problem is that i am successfully able to send mail but when click on link not able to find emailId for reset password. Gmail Link :

http://127.0.0.1:8888/abc.html?gwt.codesvr=127.0.0.1:9997#forgetPassword

client Code

sendButton.addClickHandler(new ClickHandler() {

    @Override
    public void onClick(ClickEvent event) {
        // TODO Auto-generated method stub

        greetServer.mailLinkSend(emailId.getText(),"http://"+Window.Location.getHost()+Window.Location.getPath()+Window.Location.getQueryString()+"#forgetPassword", new AsyncCallback<String>() {

            @Override
            public void onSuccess(String result) {
                // TODO Auto-generated method stub
                System.out.println("success"+result);
            }

            @Override
            public void onFailure(Throwable caught) {
                // TODO Auto-generated method stub
                System.out.println("fail");
            }
        });
    }
});

on server

public String mailLinkSend(String emailText, String link) {
               SecretKey key = KeyGenerator.getInstance("DES").generateKey(); 

// Create encrypter/decrypter class DesEncrypter encrypter = new DesEncrypter(key);

// Encrypt encrypted = encrypter.encrypt(emailText);

// Decrypt String decrypted = encrypter.decrypt(encrypted);

    String ss = "true";

            String emailMsgTxt = "Hi" + emailText + "\n" + "\n"
            + "Your Password Change Link\n" + link + "?id=" + encrypted
            + "\n Click on the above link to Reset your Password";
    String emailSubjectTxt = "Change Password Link";
    String emailFromAddress = "abc@gmail.com";
    String receipentList = emailText;

    try {
        MailUtility smtpMailSender = new MailUtility();
        smtpMailSender.postMail(receipentList, emailSubjectTxt,emailMsgTxt,   emailFromAddress);

    } catch (MessagingException messagingException) {}


    return ss;
}

MailUtility class

public class MailUtility {
    public String postMail(String recipients, String subject,
            String message, String from) throws MessagingException {

some code.... }

i have send emailId in encrypted form but i don't know how to save key for decrypted and also how to expire link after one time use and 48 hrs.


回答1:


So your problem with encryption and decryption

So the below code will help you

Note Constants.GWT_DES_KEY will be same on server and client

for example :

private final static byte[] GWT_DES_KEY = new byte[] { -110, 121, -65, 22, -60, 61, -22, -60, 21, -122, 41, -89, -89, -68, -8, 41, -119, -51, -12, -36, 19, -8, -17, 47 };

on the server:

  TripleDesCipher cipher = new TripleDesCipher();
    cipher.setKey(Constants.GWT_DES_KEY);
    try {
    enc = cipher.encrypt(String.valueOf(value));
    } catch (DataLengthException e1) {
    e1.printStackTrace();
    } catch (IllegalStateException e1) {
    e1.printStackTrace();
    } catch (InvalidCipherTextException e1) {
    e1.printStackTrace();
    }

On the client, make sure you inherit the module:
<inherits name='com.googlecode.gwt.crypto.Crypto'/>
Then:

  TripleDesCipher cipher = new TripleDesCipher();
    cipher.setKey(Constants.GWT_DES_KEY);
    String dec ="";
    try {
    dec = cipher.decrypt(enc);
    } catch (DataLengthException e) {
    e.printStackTrace();
    } catch (IllegalStateException e) {
    e.printStackTrace();
    } catch (InvalidCipherTextException e) {
    e.printStackTrace();
    }


来源:https://stackoverflow.com/questions/14618865/forget-password-link-using-gwt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!