You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
36 lines
1.1 KiB
4 years ago
|
package com.tptj.course.hg.login.username;
|
||
|
|
||
|
import com.fr.stable.CodeUtils;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
import com.fr.web.utils.WebUtils;
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
|
||
|
/**
|
||
|
* @author 秃破天际
|
||
|
* @version 10.0
|
||
|
* Created by 秃破天际 on 2021-05-12
|
||
|
**/
|
||
|
public class LoginMd5Filter extends LoginFilter {
|
||
|
|
||
|
private static final String SECRET = "123456";
|
||
|
|
||
|
protected String getUsername( HttpServletRequest req )throws Exception{
|
||
|
String sign = WebUtils.getHTTPRequestParameter(req,"sign");
|
||
|
String [] parts = sign.split("_");
|
||
|
String username = parts[0];
|
||
|
long timestamp = Long.parseLong(parts[1]);
|
||
|
long crt_time = System.currentTimeMillis();
|
||
|
if( crt_time - timestamp > 300000 || crt_time < timestamp ){
|
||
|
return StringUtils.EMPTY;
|
||
|
}
|
||
|
String source = username+timestamp+SECRET;
|
||
|
String md5 = CodeUtils.md5Encode(source,StringUtils.EMPTY,"MD5");
|
||
|
//sign = username_timestamp_md5(username+timestamp+SECRET)
|
||
|
if( StringUtils.equals(parts[2],md5) ){
|
||
|
return username;
|
||
|
}
|
||
|
return StringUtils.EMPTY;
|
||
|
}
|
||
|
|
||
|
}
|