Tabnine Logo
MPassword
Code IndexAdd Tabnine to your IDE (free)

How to use
MPassword
in
de.mhus.lib.core

Best Java code snippets using de.mhus.lib.core.MPassword (Showing top 14 results out of 315)

origin: de.mhus.lib/mhu-lib-core

/**
 * 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);
}
origin: de.mhus.lib/mhu-lib-core

/**
 * 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);
}
origin: de.mhus.lib/mhu-lib-core

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);
}
 
origin: de.mhus.lib/mhu-lib-karaf

} 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]));
origin: de.mhus.lib/mhu-lib-core

properties.put("mail.smtp.auth", "true");
properties.put("mail.user", CFG_MAIL_USER.value());
properties.put("mail.password", MPassword.decode(CFG_MAIL_PASSWORD.value()));
origin: de.mhus.lib/mhu-lib-core

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);
  }
}
origin: de.mhus.lib/mhu-lib-core

if (!isEncoded(in)) return in;
if (in.startsWith(PREFIX_ROT13))
  return Rot13.decode(in.substring(3));
origin: de.mhus.lib/mhu-lib-persistence

@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;
}
origin: de.mhus.lib/mhu-lib-core

public static String encode(METHOD method, String in) {
  return encode(method, in, (String)null);
}
origin: de.mhus.lib/mhu-lib-core

public static String encode(METHOD method, SecureString in, String secret) {
  return encode(method, in.value(), secret);
}
origin: de.mhus.lib/mhu-lib-core

public static String encode(METHOD method, String in, SecureString secret) {
  return encode(method, in, secret.value());
}
 
origin: de.mhus.lib/mhu-lib-core

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]));
}
   
origin: de.mhus.lib/mhu-lib-core

public static String encode(METHOD method, SecureString in, SecureString secret) {
  return encode(method, in.value(), secret.value());
}
 
origin: de.mhus.lib/mhu-lib-core

if (p>=0) {
  username = x.substring(0, p);
  password = MPassword.encode(x.substring(p+1));
} else {
  username = x;
de.mhus.lib.coreMPassword

Javadoc

Decode / Encode passwords. Attention: This do not give security in any way. It's only a way to deny reading the password from the screen. No algorithm will give you security in this case. Only one way algorithm is more secure. The password is not allowed to start with a ":". Only the encoded password will start with a ":" followed by the algorithm version and the encoded password. A - old X - not accepted - dummy password B: - rot13 C: - Key Id from MVault ZMD5: - md5 encoded with salt

Most used methods

  • decode
    Decode a encoded password.
  • encode
    Encode a password string be aware of special characters like umlaute. This can cause problems.
  • encodePasswordMD5
  • generate
  • isEncoded
  • validatePasswordMD5

Popular in Java

  • Reading from database using SQL prepared statement
  • onCreateOptionsMenu (Activity)
  • requestLocationUpdates (LocationManager)
  • compareTo (BigDecimal)
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now