Calculates the strength of a password.
@param pw the password to calculate the strength
@return An integer value from 0 to 100.
961248
public static double calcPasswordStrength(SecureCharArray pw) {
        ArrayList<Character> uniques = new ArrayList<Character>();
        int pwLength = pw.size();
        int i, j;

        if (pwLength <= 2)
            return 0;

        // Find character frequency
        for (i = 0; i < pwLength; i++) {
            for (j = 0; j < uniques.size(); j++) {
                if (i == j)
                    continue;
                if (pw.getCharAt(i) == uniques.get(j))
                    break;
            }
            if (j == uniques.size())
                uniques.add(pw.getCharAt(i));
        }

        double r0 = ((double) uniques.size()) / ((double) pwLength);
        if (uniques.size() == 1)
            r0 = 0;

        // length of the password - 1pt per char over 5, up to 15 for 10 pts total
        double r1 = (double) pwLength;
        if (r1 >= 15)
            r1 = 10;
        else if (r1 < 5)
            r1 = -5;
        else
            r1 -= 5;

        double quarterLen = Math.round(((double) pwLength) / 4.0);
        double num = 0;
        for (i = 0; i < pwLength; i++)
            if (!Character.isDigit(pw.getCharAt(i)))
                num++;
        num = pwLength - num;
        double c = num > quarterLen * 2.0 ? quarterLen : Math.abs(quarterLen - num);
        double r2 = 1.0 - (c / quarterLen);

        // ratio of symbols in the password
        num = 0;
        for (i = 0; i < pwLength; i++)
            if (Character.isLetterOrDigit(pw.getCharAt(i)) || pw.getCharAt(i) == '_')
                num++;
        num = pwLength - num;
        c = num > quarterLen * 2 ? quarterLen : Math.abs(quarterLen - num);
        double r3 = 1.0 - (c / quarterLen);

        // ratio of uppercase in the password
        num = 0;
        for (i = 0; i < pwLength; i++)
            if (!Character.isUpperCase(pw.getCharAt(i)))
                num++;
        num = pwLength - num;
        c = num > quarterLen * 2 ? quarterLen : Math.abs(quarterLen - num);
        double r4 = 1.0 - (c / quarterLen);

        // ratio of lower case in the password
        num = 0;
        for (i = 0; i < pwLength; i++)
            if (!Character.isLowerCase(pw.getCharAt(i)))
                num++;
        num = pwLength - num;
        c = num > quarterLen * 2 ? quarterLen : Math.abs(quarterLen - num);
        double r5 = 1.0 - (c / quarterLen);

        double pwStrength = (((r0 + r2 + r3 + r4 + r5) / 5.0f) * 100.0f) + r1;

        if (pwStrength < 0.0f)
            pwStrength = 0.0f;
        if (pwStrength > 100.0f)
            pwStrength = 100.0f;

        return pwStrength;
    }
68393
private float getPasswordStrength() {
        int absoluteScore = 0;
        CharSequence password = getView().getText();

        for (Constraint<CharSequence> constraint : constraints) {
            if (constraint.isSatisfied(password)) {
                absoluteScore++;
            }
        }

        return ((float) absoluteScore / (float) constraints.size());
    }
738417
public static int ipowi(int x, int p) {
    if(p <= 2) {
      return (int) FastMath.powFast(x, p);
    }
    int tmp = x, ret = (p & 1) == 1 ? x : 1;
    while(true) {
      tmp *= tmp;
      p >>= 1;
      if(p == 1) {
        return ret * tmp;
      }
      if((p & 1) != 0) {
        ret *= tmp;
      }
    }
  }
1264657
def pow2(x: int, p: int) -> int:
    """"""
    while p > 0:
        x = x * x % q
        p -= 1
    return x
788684
public void setCredentials(final String user, final String pw) {
    if (user == null) {
      credentials = null;
    } else {
      credentials = new UsernamePasswordCredentials(user, pw);
    }
  }
655000
def get_server_premaster_secret(self, password_verifier, server_private, client_public, common_secret):
        
        return pow((client_public * pow(password_verifier, common_secret, self._prime)), server_private, self._prime)
1295887
public AuthenticationConfigurationBuilder password(String password) {
      this.password = password != null ? password.toCharArray() : null;
      return enable();
   }
195499
public function get( $length, $strength = 0 )
	{
		if( !is_int( $length ) )															//  Length is not Integer
			throw new InvalidArgumentException( 'Length must be an Integer.' );
		if( !$length )																		//  Length is 0
			throw new InvalidArgumentException( 'Length must greater than 0.' );
		if( !is_int( $strength ) )															//  Stength is not Integer
			throw new InvalidArgumentException( 'Strength must be an Integer.' );
		if( $strength && $strength > 100 )													//  Strength is to high
			throw new InvalidArgumentException( 'Strength must be at most 100.' );
		if( $strength && $strength < -100 )													//  Strength is to low
			throw new InvalidArgumentException( 'Strength must be at leastt -100.' );

		$length	= abs( $length );															//  absolute Length
		$pool	= $this->createPool();														//  create Sign Pool
		if( !strlen( $pool ) )																//  Pool is empty
			throw new RuntimeException( 'No usable signs defined.' );
		if( $this->unique && $length >= strlen( $pool ) )									//  Pool is smaller than Length
			throw new UnderflowException( 'Length must be lower than Number of usable Signs in "unique" Mode.' );

		$random	= $this->createString( $length, $pool );									//  randomize String
		if( !$strength )																	//  no Strength needed
			return $random;

		$turn	= 0;
		do
		{
			$currentStrength	= Alg_Crypt_PasswordStrength::getStrength( $random );		//  calculate Strength of random String
			if( $currentStrength >= $strength )												//  random String is strong enough
				return $random;
			$random	= $this->createString( $length, $pool );								//  randomize again
			$turn++;																		//  count turn
		}
		while( $turn < $this->maxTurns );													//  break if to much turns
		throw new RuntimeException( 'Strength Score '.$strength.' not reached after '.$turn.' Turns.' );
	}
1098293
public double percentile(double p) {
    long[] counts = new long[PercentileBuckets.length()];
    for (int i = 0; i < counts.length; ++i) {
      counts[i] = counterFor(i).count();
    }
    return PercentileBuckets.percentile(counts, p);
  }
613096
private void verifyPasswordStrength() {
        if (isEnabled() && !constraints.isEmpty() && !TextUtils.isEmpty(getText())) {
            float score = getPasswordStrength();
            adaptHelperText(score);
        } else {
            setHelperText(regularHelperText);
        }
    }
785669
@Override
  public double plus(double w1, double w2) {
    if (!isMember(w1) || !isMember(w2)) {
      return Double.NEGATIVE_INFINITY;
    }

    return w1 + w2;
  }
292760
private boolean doUserPasswordAuthentication(Socket s,
                                                InputStream in,
                                                OutputStream out) 
                                                throws IOException{
     int version = in.read();
     if(version != 1) return false;
     int ulen = in.read();
     if(ulen < 0) return false;
     byte[] user = new byte[ulen];
     in.read(user);
     int plen = in.read();
     if(plen < 0) return false;
     byte[] password = new byte[plen];
     in.read(password);

     if(validator.isUserValid(new String(user), new String(password),s)){
       //System.out.println("user valid");
       out.write(new byte[]{1,0});
     }else{
       //System.out.println("user invalid");
       out.write(new byte[]{1,1});
       return false;
     }

     return true;
   }
527296
public static double inverfc(double p) {
        double x, err, t, pp;
        if (p >= 2.0) {
            return -100.;
        }
        if (p <= 0.0) {
            return 100.;
        }
        pp = (p < 1.0) ? p : 2. - p;
        t = Math.sqrt(-2. * Math.log(pp / 2.));
        x = -0.70711 * ((2.30753 + t * 0.27061) / (1. + t * (0.99229 + t * 0.04481)) - t);
        for (int j = 0; j < 2; j++) {
            err = erfc(x) - pp;
            x += err / (1.12837916709551257 * Math.exp(-x * x) - x * err);
        }
        return (p < 1.0 ? x : -x);
    }
944747
public static boolean validatePassword(BrokerSession session, String password) {
        password = encrypt(password, session.getServerCaps().getCipherKey());
        return session.callRPCBool("RGCWFUSR VALIDPSW", password);
    }
129742
public void setPassword(final String psw) {
        if (StringUtils.isNotBlank(psw)) {
            LOGGER.debug("Configured Jasypt password");
            jasyptInstance.setPassword(psw);
        }
    }
440564
int guessPayloadLength() {
    int length = 0;
    byte[] payload = (byte[])getPayload().getField(JmsBytesBodyAccess.BODY_DATA_VALUE);
    if (payload != null) {
      length = payload.length + 24;
    }
    return length;
  }
329379
@Override
	public char[] getPropertyPassword(String key, char[] defaultPassword)
	{
		char[] bVal = null;
		String sVal = getSecureProperty(key);
		if ((sVal != null) && (sVal.length() > 0))
		{
			bVal = sVal.toCharArray();
		}
		else
		{
			bVal = defaultPassword;
		}
		return bVal;

	}