Package org.owasp.passfault

Examples of org.owasp.passfault.PathCost


  public void twoPattern_middle() {
    PasswordAnalysis pa = new PasswordAnalysis("12345");
    pa.foundPattern(new PasswordPattern(1, 1, "2", 2, "testPattern"));
    pa.foundPattern(new PasswordPattern(3, 1, "4", 2, "testPattern"));

    PathCost patterns = pa.calculateHighestProbablePatterns();

    List<PasswordPattern> list = patterns.getPath();
    assertEquals(5, list.size());
    double result = patterns.getTotalCost();
    System.out.println("cost=" + result);

    double expected = Math.pow(10, 3) * 4;
    assertEquals(expected, result, 0.5);
  }
View Full Code Here


    pa.foundPattern(new PasswordPattern(1, 2, "23", 15, "worstPattern"));
    pa.foundPattern(new PasswordPattern(1, 2, "23", 4, "bestPattern"));
    pa.foundPattern(new PasswordPattern(1, 2, "23", 20, "worsePattern"));
    pa.foundPattern(new PasswordPattern(1, 2, "23", 23, "worserPattern"));

    PathCost patterns = pa.calculateHighestProbablePatterns();

    List<PasswordPattern> list = patterns.getPath();
    assertEquals(3, list.size());
    double result = patterns.getTotalCost();
    System.out.println("cost=" + result);
    double expected = Math.pow(10, 3) * 4;
    assertEquals(expected, result, 0.5);
  }
View Full Code Here

    pa.foundPattern(new PasswordPattern(4, 1, "5", 15, "badPattern"));
    pa.foundPattern(new PasswordPattern(4, 1, "5", 20, "worserPattern"));
    pa.foundPattern(new PasswordPattern(4, 1, "5", 4, "bestPattern"));
    pa.foundPattern(new PasswordPattern(4, 1, "5", 23, "worstPattern"));

    PathCost patterns = pa.calculateHighestProbablePatterns();

    List<PasswordPattern> list = patterns.getPath();
    assertEquals(4, list.size());
    double result = patterns.getTotalCost();
    System.out.println("cost=" + result);
    double expected = Math.pow(10, 1) * 4 * 4 * 4;
    assertEquals(expected, result, 0.5);
  }
View Full Code Here

  @Test
  public void allPossibleRandom() {
    PasswordAnalysis pa = new PasswordAnalysis("37384756683");
    RandomAddAll.RandomAddAll(pa);
    PathCost patterns = pa.calculateHighestProbablePatterns();

    List<PasswordPattern> list = patterns.getPath();
    assertEquals(1, list.size());
    double result = patterns.getTotalCost();
    System.out.println("cost=" + result);
  }
View Full Code Here

   */
  @Override
  public PathCost calculateHighestProbablePatterns() {
    if (finalResults == null) {
      log.log(Level.INFO, "Calculating the highest probable combination of {0} finders\n", getPossiblePatternCount());
      PathCost cost = smallestCost(0);
      cost = postAnalysis(cost);
      log.log(Level.FINE, "smallestCost took {0} iterations", counter);

      for (AnalysisListener observer : analysisListeners) {
        observer.foundHighestProbablePatterns(cost);
View Full Code Here

   * @param startChar
   * @return List of finders including cost
   */
  private PathCost smallestCost(int startChar) {
    double smallestCost = Double.MAX_VALUE;
    PathCost smallestCostPath = new PathCost(this);
    for (int i = startChar; i < password.length(); i++) {
      List<PasswordPattern> ithPatterns = foundPatterns.get(i);
      if (ithPatterns != null) {
        PathCost pathCost = ithSmallestCost(ithPatterns);
        counter++;

        //random characters between startChar and the next found pattern
        PasswordPattern randomPattern = getRandomPattern(startChar, i);

        if (randomPattern != null) {
          pathCost.addPattern(randomPattern);
        }
        if (pathCost.getRelativeCost() < smallestCost) {
          smallestCost = pathCost.getRelativeCost();
          smallestCostPath = pathCost;
        }
      }
    }
    if (smallestCostPath.getPath().size() == 0) {
View Full Code Here

   * @return result of the smallest result of calling smallestCost on all
   * finders in the list
   */
  private PathCost ithSmallestCost(List<PasswordPattern> ithPatterns) {
    double smallestCost = Double.MAX_VALUE;
    PathCost smallestCostPath = null;
    for (PasswordPattern pattern : ithPatterns) {
      PathCost costPath = smallestCost(pattern.getStartIndex() + pattern.getLength());
      costPath.addPattern(pattern);
      double cost = costPath.getRelativeCost();
      if (cost < smallestCost) {
        smallestCost = cost;
        smallestCostPath = costPath;
      }
    }
View Full Code Here

    throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  public PathCost calculateHighestProbablePatterns() {
    PathCost pathCost = new PathCost(this);
    for (PasswordPattern patt : this.foundPatterns) {
      pathCost.addPattern(patt);
    }
    return pathCost;
  }
View Full Code Here

public class RepeatingPatternFinder {

  public static final String DUPLICATE_PATTERN = "DUPLICATE";

  public PathCost process(PathCost cost, PasswordResults password) {
    PathCost newPath = new PathCost(password);
    List<PasswordPattern> path = cost.getPath();
    for (int len = path.size() - 1, i = len; i >= 0; i--) {
      PasswordPattern pass = path.get(i);
      boolean foundDuplicate = false;
      for (int j = i - 1; j >= 0; j--) {
        PasswordPattern toCompare = path.get(j);
        if (!toCompare.getName().equals(RandomPattern.RANDOM_PATTERN)
            && toCompare.getName().equals(pass.getName())
            && toCompare.getMatchString().equals(pass.getMatchString())) {
          //repeated-duplicate pattern instance
          foundDuplicate = true;
          break;
        }
      }
      if (foundDuplicate) {
        PasswordPattern dupp = new PasswordPattern(pass.getStartIndex(), pass.getLength(), pass.getMatchString(), 1,
            "Duplication of an earlier pattern: " + pass.getName(), DUPLICATE_PATTERN, null);
        newPath.addPattern(dupp);
      } else {
        newPath.addPattern(pass);
      }
    }
    return newPath;
  }
View Full Code Here

  }

  @Test
  public void randomNumbers() {
    PasswordAnalysis_Unoptimized pa = new PasswordAnalysis_Unoptimized("1234");
    PathCost patterns = pa.calculateHighestProbablePatterns();
   
    List<PasswordPattern> list = patterns.getPath();
    assertEquals(1, list.size());
    double result = patterns.getTotalCost()
    System.out.println("cost="+result);
    double expected = Math.pow(10,4);
    assertEquals(expected, result, 0.5);
  }
View Full Code Here

TOP

Related Classes of org.owasp.passfault.PathCost

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.