2

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

我的问题是我可以成功发送邮件,但是当点击链接时无法找到 emailId 来重置密码。 邮箱链接:

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

// 解密字符串解密 = 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 小时后使链接过期。

4

1 回答 1

1

所以你的加密和解密问题

所以下面的代码会帮助你

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

例如 :

私有最终静态字节[] GWT_DES_KEY = 新字节[] { -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();
    }
于 2013-01-31T07:58:30.947 回答