自己定义一个密码规则,可逆
ex.
String strPwd = "1234567";
String strRule = "UUU#UUU*UUU&";
String strRulePwd ="123#456*7&";
rule的意思是每隔三位插一个字符,再把字符串插入自定义字符后保存,登陆时也是!
我想你应该可以搞定了吧?
具体String的操作可查JDK!
ex.
String strPwd = "1234567";
String strRule = "UUU#UUU*UUU&";
String strRulePwd ="123#456*7&";
rule的意思是每隔三位插一个字符,再把字符串插入自定义字符后保存,登陆时也是!
我想你应该可以搞定了吧?
具体String的操作可查JDK!
if (s == null) {
return null;
}
return (new sun.misc.BASE64Encoder()).encode(s.getBytes());
}// 将 BASE64 编码的字符串 s 进行解码
public String getFromBASE64(String s) {
if (s == null) {
return null;
}
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b);
}
catch (Exception e) {
return null;
}
}
* Used by the hash method.
*/
private static MessageDigest digest = null; /**
* Hashes a String using the Md5 algorithm and returns the result as a
* String of hexadecimal numbers. This method is synchronized to avoid
* excessive MessageDigest object creation. If calling this method becomes
* a bottleneck in your code, you may wish to maintain a pool of
* MessageDigest objects instead of using this method.
* <p>
* A hash is a one-way function -- that is, given an
* input, an output is easily computed. However, given the output, the
* input is almost impossible to compute. This is useful for passwords
* since we can store the hash and a hacker will then have a very hard time
* determining the original password.
* <p>
* Every time a user logs in, we simply
* take their plain text password, compute the hash, and compare the
* generated hash to the stored hash. Since it is almost impossible that
* two passwords will generate the same hash, we know if the user gave us
* the correct password or not. The only negative to this system is that
* password recovery is basically impossible. Therefore, a reset password
* method is used instead.
*
* @param data the String to compute the hash of.
* @return a hashed version of the passed-in String
*/
public synchronized static final String hash(String data) {
if (digest == null) {
try {
digest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException nsae) {
System.err.println("Failed to load the MD5 MessageDigest. " +
"Jive will be unable to function normally.");
nsae.printStackTrace();
}
}
// Now, compute hash.
digest.update(data.getBytes());
return encodeHex(digest.digest());
}
* Turns an array of bytes into a String representing each byte as an
* unsigned hex number.
* <p>
* Method by Santeri Paavolainen, Helsinki Finland 1996<br>
* (c) Santeri Paavolainen, Helsinki Finland 1996<br>
* Distributed under LGPL.
*
* @param bytes an array of bytes to convert to a hex-string
* @return generated hex string
*/
public static final String encodeHex(byte[] bytes) {
StringBuffer buf = new StringBuffer(bytes.length * 2);
int i; for (i = 0; i < bytes.length; i++) {
if (((int) bytes[i] & 0xff) < 0x10) {
buf.append("0");
}
buf.append(Long.toString((int) bytes[i] & 0xff, 16));
}
return buf.toString();
}
* Updates the digest using the specified array of bytes.
*
* @param input the array of bytes.
*/
public void update(byte[] input) {
engineUpdate(input, 0, input.length);
state = IN_PROGRESS;
}