使用get忘记密码链接

时间:2013-01-31 05:07:20

标签: gwt gmail des gwt-ext

在我的网站中,我有一个链接忘记密码,当我点击此链接时,页面将会出现,所以我们填写emailId并发送邮件到特定的gmailid(在这封邮件中我们必须生成一个链接) 。当我们点击生成的链接页面打开重置密码(如新密码ar确认密码)。

我的问题是我能够成功发送邮件,但点击链接时无法找到emailId 用于重置密码。 Gmail链接:

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

客户代码

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");
            }
        });
    }
});
服务器上的

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

//创建加密/解密器类 DesEncrypter encrypter = new DesEncrypter(key);

//加密 encrypted = encrypter.encrypt(emailText);

//解密 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类

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

一些代码...... }

我已经以加密形式发送emailId,但我不知道如何保存解密密钥以及如何在一次使用和48小时后过期链接。

1 个答案:

答案 0 :(得分:1)

所以加密和解密的问题

以下代码将帮助您

注意服务器和客户端上的Constants.GWT_DES_KEY相同

例如:

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     };

在服务器上:

  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();
    }
相关问题