-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentropyAdded
216 lines (187 loc) · 5.5 KB
/
entropyAdded
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package com.nulabinc.zxcvbn;
import com.nulabinc.zxcvbn.matchers.Match;
import java.util.ArrayList;
import java.util.List;
public class Strength {
private CharSequence password;
private double guesses;
private double guessesLog10;
private AttackTimes.CrackTimeSeconds crackTimeSeconds;
private AttackTimes.CrackTimesDisplay crackTimesDisplay;
private int score;
private Feedback feedback;
private List<Match> sequence;
private long calcTime;
/**
* Default constructor.
*
* @deprecated This constructor is discouraged from use as it does not ensure all fields are
* initialized properly. Instead, use the {@link #Strength(CharSequence, double, List, long)}
* constructor to provide all necessary data.
*/
@Deprecated
public Strength() {
this.sequence = new ArrayList<>();
}
/**
* Constructs a Strength object with the given parameters.
*
* @param password The password for which strength is calculated.
* @param guesses Estimated number of guesses needed to crack the password.
* @param sequence A list of matching patterns found in the password.
* @param calcTime Time taken to calculate the password's strength.
*/
public Strength(CharSequence password, double guesses, List<Match> sequence, long calcTime) {
this.password = password;
this.guesses = guesses;
this.guessesLog10 = Scoring.log10(guesses);
if (sequence == null) {
sequence = new ArrayList<>();
}
this.sequence = sequence;
AttackTimes attackTimes = TimeEstimates.estimateAttackTimes(guesses);
this.crackTimeSeconds = attackTimes.getCrackTimeSeconds();
this.crackTimesDisplay = attackTimes.getCrackTimesDisplay();
this.score = attackTimes.getScore();
this.feedback = Feedback.getFeedback(attackTimes.getScore(), sequence);
this.calcTime = calcTime;
}
public CharSequence getPassword() {
return password;
}
/**
* Sets the password.
*
* @deprecated Use constructor for initialization. Modifying after instantiation is not
* recommended.
*/
@Deprecated
public void setPassword(CharSequence password) {
this.password = password;
}
public double getGuesses() {
return guesses;
}
/**
* Sets the estimated number of guesses.
*
* @deprecated Use constructor for initialization. Modifying after instantiation is not
* recommended.
*/
@Deprecated
public void setGuesses(double guesses) {
this.guesses = guesses;
}
public double getGuessesLog10() {
return guessesLog10;
}
/**
* Sets the logarithm (base 10) of the estimated number of guesses.
*
* @deprecated Use constructor for initialization. Modifying after instantiation is not
* recommended.
*/
@Deprecated
public void setGuessesLog10(double guessesLog10) {
this.guessesLog10 = guessesLog10;
}
public AttackTimes.CrackTimeSeconds getCrackTimeSeconds() {
return crackTimeSeconds;
}
/**
* Sets the crack time in seconds.
*
* @deprecated Use constructor for initialization. Modifying after instantiation is not
* recommended.
*/
@Deprecated
public void setCrackTimeSeconds(AttackTimes.CrackTimeSeconds crackTimeSeconds) {
this.crackTimeSeconds = crackTimeSeconds;
}
public AttackTimes.CrackTimesDisplay getCrackTimesDisplay() {
return crackTimesDisplay;
}
/**
* Sets the display times for crack attempts.
*
* @deprecated Use constructor for initialization. Modifying after instantiation is not
* recommended.
*/
@Deprecated
public void setCrackTimesDisplay(AttackTimes.CrackTimesDisplay crackTimesDisplay) {
this.crackTimesDisplay = crackTimesDisplay;
}
public int getScore() {
return score;
}
/**
* Sets the score.
*
* @deprecated Use constructor for initialization. Modifying after instantiation is not
* recommended.
*/
@Deprecated
public void setScore(int score) {
this.score = score;
}
public Feedback getFeedback() {
return feedback;
}
/**
* Sets the feedback.
*
* @deprecated Use constructor for initialization. Modifying after instantiation is not
* recommended.
*/
@Deprecated
public void setFeedback(Feedback feedback) {
this.feedback = feedback;
}
public List<Match> getSequence() {
return sequence;
}
/**
* Sets the sequence of matches.
*
* @deprecated Use constructor for initialization. Modifying after instantiation is not
* recommended.
*/
@Deprecated
public void setSequence(List<Match> sequence) {
if (sequence == null) {
sequence = new ArrayList<>();
}
this.sequence = sequence;
}
public long getCalcTime() {
return calcTime;
}
/**
* Sets the calculation time.
*
* @deprecated Use constructor for initialization. Modifying after instantiation is not
* recommended.
*/
@Deprecated
public void setCalcTime(long calcTime) {
this.calcTime = calcTime;
}
/**
* Returns the entropy of the password based on the number of guesses.
* Entropy is calculated using the base-2 logarithm of the guesses.
*
* @return The entropy of the password in bits.
*/
public double getEntropy() {
return Math.log(guesses) / Math.log(2);
}
/** Attempts to wipe any sensitive content from the object. */
public void wipe() {
WipeableString.wipeIfPossible(password);
for (Match match : sequence) {
WipeableString.wipeIfPossible(match.token);
WipeableString.wipeIfPossible(match.baseToken);
WipeableString.wipeIfPossible(match.matchedWord);
}
}
}