/** * Check if the passwords are equals. The password could also be hashes. * * @param storedPass * @param givenPass * @return true if found the are identically */ public static boolean equals(String storedPass, String givenPass) { if (storedPass == null || givenPass == null) return false; // do not accept empty pass storedPass = storedPass.trim(); givenPass = givenPass.trim(); if (givenPass.length() == 0) return false; if (givenPass.startsWith("`")) { //givenPass = decode(givenPass); return false; // given password can't be encoded, this will give the ability to use the encoded string itself as password instead of clear text } if (storedPass.startsWith(PREFIX)) { if (storedPass.startsWith(PREFIX_HASH_MD5)) { return validatePasswordMD5(givenPass, storedPass); } storedPass = decode(storedPass); } return storedPass.equals(givenPass); }
/** * Encode a password string be aware of special characters like umlaute. This * can cause problems. * * @param in * @return encoded string */ public static String encode(String in) { return encode(METHOD.ROT13,in, (String)null); }
public static String generate(int min, int max, boolean upper, boolean numbers, boolean specials) { char[] symbols = new char[ 75 - 3 ]; int i = 0; for (char c = 'a'; c <= 'z'; c++) if ( c != 'l') symbols[i++] = c; if (upper) for (char c = 'A'; c <= 'Z'; c++) if (c != 'I' && c != 'O') symbols[i++] = c; if (numbers) for (char c = '0'; c <= '9'; c++) symbols[i++] = c; if (specials) { symbols[i++] = '_'; symbols[i++] = '-'; symbols[i++] = '.'; symbols[i++] = '!'; symbols[i++] = '+'; symbols[i++] = '/'; symbols[i++] = '@'; symbols[i++] = '#'; symbols[i++] = ';'; } return generate(max == min ? min : (random.nextInt(max-min)+max), symbols, i); }
} else if (cmd.equals("encodepasswordrot13")) { System.out.println( MPassword.encode(MPassword.TYPE_ROT13, parameters[0], null) ); System.out.println( MPassword.encode(MPassword.TYPE_RSA, parameters[1], parameters[0]) ); } else if (cmd.equals("decodepassword")) { System.out.println( MPassword.decode(parameters[0]));
properties.put("mail.smtp.auth", "true"); properties.put("mail.user", CFG_MAIL_USER.value()); properties.put("mail.password", MPassword.decode(CFG_MAIL_PASSWORD.value()));
public static String encode(METHOD method, String in, String secret) { if (in == null) return null; if (isEncoded(in)) return in; switch (method) { case DUMMY: // empty dummy password return PREFIX_DUMMY; case ROT13: return PREFIX_ROT13 + Rot13.encode(in); case RSA: MVault vault = MVaultUtil.loadDefault(); VaultEntry entry = vault.getEntry(UUID.fromString(secret)); if (entry == null) throw new MRuntimeException("key not found",secret); try { AsyncKey key = MVaultUtil.adaptTo(entry, AsyncKey.class); return PREFIX_RSA + entry.getId() + ":" + MCrypt.encodeWithSalt(key, in); } catch (Exception e) { throw new MRuntimeException(e); } case HASH_MD5: return PREFIX_HASH_MD5 + encodePasswordMD5(secret); default: throw new MRuntimeException("unknown encode method",method); } }
if (!isEncoded(in)) return in; if (in.startsWith(PREFIX_ROT13)) return Rot13.decode(in.substring(3));
@Override public InternalDbConnection createConnection() throws Exception { // ResourceNode concon = config.getNode("connection"); String driver = config.getExtracted("driver"); String url = config.getExtracted("url"); String user = config.getExtracted("user"); String pass = config.getExtracted("pass"); if (!MString.isEmpty(driver)) { if (activator != null) activator.getClazz(driver); else Class.forName(driver); } log().t(driver,url,user); Connection con = DriverManager.getConnection(url,user,MPassword.decode(pass)); getDialect().prepareConnection(con); JdbcConnection dbCon = new JdbcConnection(this,con); long timeoutUnused = MPeriod.toMilliseconds( config.getExtracted("timeout_unused"), 0 ); long timeoutLifetime = MPeriod.toMilliseconds( config.getExtracted("timeout_lifetime"), 0 ); if (timeoutUnused > 0) dbCon.setTimeoutUnused(timeoutUnused); if (timeoutLifetime > 0) dbCon.setTimeoutLifetime(timeoutLifetime); return dbCon; }
public static String encode(METHOD method, String in) { return encode(method, in, (String)null); }
public static String encode(METHOD method, SecureString in, String secret) { return encode(method, in.value(), secret); }
public static String encode(METHOD method, String in, SecureString secret) { return encode(method, in, secret.value()); }
public static void main(String[] args) { if (args.length == 0) { System.out.print("decoded: "); TextReader reader = new TextReader(System.in); args = new String[] { reader.readLine() }; } System.out.println("encoded: " + encode(args[0])); }
public static String encode(METHOD method, SecureString in, SecureString secret) { return encode(method, in.value(), secret.value()); }
if (p>=0) { username = x.substring(0, p); password = MPassword.encode(x.substring(p+1)); } else { username = x;