本文介绍了忘记使用gwt的密码链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的网站中,我有一个链接忘记密码,当我点击这个链接时,一个页面会出现,所以我们填写emailId并发送邮件到特定的gmailid(在这封邮件中我们必须生成一个链接) 。当我们点击生成的链接页面打开重置密码(如新密码,确认密码)。
我的问题是,我成功地能够发送邮件,但当点击在链接无法找到emailId
重置密码。
Gmail链接:
http://127.0.0.1:8888/abc。 html?gwt.codesvr = 127.0.0.1:9997#忘记密码
客户端代码
sendButton.addClickHandler(new ClickHandler(){
@Override
public void onClick(ClickEvent event){
// TODO自动生成的方法存根
greetServer.mailLinkSend(emailId.getText(),http://+ Window.Location.getHost() + Window.Location.getPath()+ Window.Location.getQueryString()+#forgetPassword,新的AsyncCallback< String>(){
$ b $ @覆盖
public void onSuccess ){
// TODO自动生成的方法存根
System.out.println(success+ result);
}
@Override
public void onFailure(Throwable caught){
// TODO自动生成的方法存根
S ystem.out.println( 失败);
}
});
}
});
在服务器上
public String mailLinkSend(String emailText,String link){
SecretKey key = KeyGenerator.getInstance(DES)。generateKey();
//创建加密器/解密器类
DesEncrypter加密器= new DesEncrypter(key);
//加密
encrypted = encrypter.encrypt(emailText);
$ b //解密
字符串解密= encrypter.decrypt(加密);
String ss =true;
字符串emailMsgTxt =嗨+ emailText +\\\
+\\\
+您的密码更改链接\\\
+ link +?id = +加密
+\\\
点击上面的链接重置您的密码;
字符串emailSubjectTxt =更改密码链接;
字符串emailFromAddress [email protected];
String receipentList = emailText;
尝试{
MailUtility smtpMailSender = new MailUtility();
smtpMailSender.postMail(receipentList,emailSubjectTxt,emailMsgTxt,emailFromAddress);
$ b $ catch(MessagingException messagingException){}
return ss;
}
MailUtility类
public class MailUtility {
public String postMail(String recipients,String subject,
String message,String from)throws MessagingException {
一些代码....
}
我发送emailId以加密形式,但我不知道如何保存密钥进行解密,以及如何在一次性使用和48小时后过期链接。 解决方案
>
所以你的加密和解密问题
所以下面的代码会帮助你
注意常量.GTT_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();
}
在客户端上,确保你继承了这个模块:
< inherits name ='com.googlecode.gwt.crypto.Crypto'/>
然后:
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();
}
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 emailIdfor 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 = "[email protected]";
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.
解决方案
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();
}
这篇关于忘记使用gwt的密码链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!