|
59 | 59 |
|
60 | 60 | public class PasswordStrength extends LessonAdapter
|
61 | 61 | {
|
62 |
| - private Map<String, Password> passwords = new TreeMap<String, Password>() {{ |
63 |
| - put("pass1", new Password("123456", "seconds", "0", "dictionary based, in top 10 most used passwords")); |
64 |
| - put("pass2", new Password("abzfezd", "seconds", "2", "26 chars on 7 positions, 8 billion possible combinations")); |
65 |
| - put("pass3", new Password("a9z1ezd", "seconds", "19", "26 + 10 chars on 7 positions = 78 billion possible combinations")); |
66 |
| - put("pass4", new Password("aB8fEzDq", "hours", "15", "26 + 26 + 10 chars on 8 positions = 218 trillion possible combinations")); |
67 |
| - put("pass5", new Password("z8!E?7D$", "days", "20", "96 chars on 8 positions = 66 quintillion possible combinations")); |
68 |
| - put("pass6", new Password("My 1st Password!: Redd", "septillion years", "322", "96 chars on 22 positions = 40 tredecillion possible combinations")); |
69 |
| - }}; |
70 |
| - |
71 |
| - private class Password { |
72 |
| - |
73 |
| - String password; |
74 |
| - String timeUnit; |
75 |
| - String answer; |
76 |
| - private String explanation; |
77 |
| - |
78 |
| - public Password(String password, String timeUnit, String answer, String explanation) { |
79 |
| - this.password = password; |
80 |
| - this.timeUnit = timeUnit; |
81 |
| - this.answer = answer; |
82 |
| - this.explanation = explanation; |
83 |
| - } |
84 |
| - } |
85 |
| - |
86 |
| - private boolean checkSolution(WebSession s) throws ParameterNotFoundException { |
87 |
| - boolean allCorrect = true; |
88 |
| - for ( int i = 1; i <= passwords.size(); i++ ) { |
89 |
| - String key = "pass" + i; |
90 |
| - allCorrect = allCorrect && s.getParser().getStringParameter(key, "").equals(passwords.get(key).answer); |
91 |
| - } |
92 |
| - return allCorrect; |
93 |
| - } |
94 |
| - |
95 |
| - /** |
96 |
| - * Description of the Method |
97 |
| - * |
98 |
| - * @param s |
99 |
| - * Description of the Parameter |
100 |
| - * @return Description of the Return Value |
101 |
| - */ |
102 |
| - protected Element createContent(WebSession s) |
103 |
| - { |
104 |
| - ElementContainer ec = new ElementContainer(); |
105 |
| - |
106 |
| - try |
107 |
| - { |
108 |
| - if (checkSolution(s)) |
109 |
| - { |
110 |
| - makeSuccess(s); |
111 |
| - ec.addElement(new BR()); |
112 |
| - ec.addElement(new StringElement("As a guideline not bound to a single solution.")); |
113 |
| - ec.addElement(new BR()); |
114 |
| - ec.addElement(new StringElement("Assuming the calculations per second 4 billion: ")); |
115 |
| - ec.addElement(new BR()); |
116 |
| - OL ol = new OL(); |
117 |
| - for ( Password password : passwords.values()) { |
118 |
| - ol.addElement(new LI(String.format("%s - %s %s (%s)", password.password, password.answer, password.timeUnit, password.explanation))); |
119 |
| - } |
120 |
| - ec.addElement(ol); |
121 |
| - } else |
122 |
| - { |
123 |
| - ec.addElement(new BR()); |
124 |
| - ec.addElement(new StringElement("How much time would a desktop PC take to crack these passwords?")); |
125 |
| - ec.addElement(new BR()); |
126 |
| - ec.addElement(new BR()); |
127 |
| - Table table = new Table(); |
128 |
| - for ( Entry<String, Password> entry : passwords.entrySet()) { |
129 |
| - TR tr = new TR(); |
130 |
| - TD td1 = new TD(); |
131 |
| - TD td2 = new TD(); |
132 |
| - Input input1 = new Input(Input.TEXT, entry.getKey(), ""); |
133 |
| - td1.addElement(new StringElement("Password = " + entry.getValue().password)); |
134 |
| - td2.addElement(input1); |
135 |
| - td2.addElement(new StringElement(" " + entry.getValue().timeUnit)); |
136 |
| - tr.addElement(td1); |
137 |
| - tr.addElement(td2); |
138 |
| - table.addElement(tr); |
139 |
| - } |
140 |
| - ec.addElement(table); |
141 |
| - ec.addElement(new BR()); |
142 |
| - ec.addElement(new BR()); |
143 |
| - Div div = new Div(); |
144 |
| - div.addAttribute("align", "center"); |
145 |
| - Element b = ECSFactory.makeButton("Go!"); |
146 |
| - div.addElement(b); |
147 |
| - ec.addElement(div); |
148 |
| - } |
149 |
| - } catch (Exception e) |
150 |
| - { |
151 |
| - s.setMessage("Error generating " + this.getClass().getName()); |
152 |
| - e.printStackTrace(); |
153 |
| - } |
154 |
| - |
155 |
| - |
156 |
| - return (ec); |
157 |
| - } |
158 |
| - |
159 |
| - /** |
160 |
| - * Gets the hints attribute of the HelloScreen object |
161 |
| - * |
162 |
| - * @return The hints value |
163 |
| - */ |
164 |
| - public List<String> getHints(WebSession s) |
165 |
| - { |
166 |
| - List<String> hints = new ArrayList<String>(); |
167 |
| - hints.add("Copy the passwords into the code checker."); |
168 |
| - return hints; |
169 |
| - } |
170 |
| - |
171 |
| - /** |
172 |
| - * Gets the ranking attribute of the HelloScreen object |
173 |
| - * |
174 |
| - * @return The ranking value |
175 |
| - */ |
176 |
| - private final static Integer DEFAULT_RANKING = new Integer(6); |
177 |
| - |
178 |
| - protected Integer getDefaultRanking() |
179 |
| - { |
180 |
| - return DEFAULT_RANKING; |
181 |
| - } |
182 |
| - |
183 |
| - protected Category getDefaultCategory() |
184 |
| - { |
185 |
| - return Category.AUTHENTICATION; |
186 |
| - } |
187 |
| - |
188 |
| - public String getInstructions(WebSession s) |
189 |
| - { |
190 |
| - String instructions = "The accounts of your web application are only as save as the passwords. " |
191 |
| - + "For this exercise, your job is to test several passwords on <a href=\"https://howsecureismypassword.net\" target=\"_blank\">https://howsecureismypassword.net</a>. " |
192 |
| - + " You must test all 6 passwords at the same time...<br>" |
193 |
| - + "<b> On your applications you should set good password requirements! </b>"; |
194 |
| - return (instructions); |
195 |
| - } |
196 |
| - |
197 |
| - /** |
198 |
| - * Gets the title attribute of the HelloScreen object |
199 |
| - * |
200 |
| - * @return The title value |
201 |
| - */ |
202 |
| - public String getTitle() |
203 |
| - { |
204 |
| - return ("Password Strength"); |
205 |
| - } |
206 |
| - |
207 |
| - public Element getCredits() |
208 |
| - { |
209 |
| - return super.getCustomCredits("Created by: Reto Lippuner, Marcel Wirth", new StringElement("")); |
210 |
| - } |
| 62 | + private Map<String, Password> passwords = new TreeMap<String, Password>() {{ |
| 63 | + put("pass1", new Password("123456", "seconds", "0", "dictionary based, in top 10 most used passwords")); |
| 64 | + put("pass2", new Password("abzfezd", "seconds", "2", "26 chars on 7 positions, 8 billion possible combinations")); |
| 65 | + put("pass3", new Password("a9z1ezd", "seconds", "19", "26 + 10 chars on 7 positions = 78 billion possible combinations")); |
| 66 | + put("pass4", new Password("aB8fEzDq", "hours", "15", "26 + 26 + 10 chars on 8 positions = 218 trillion possible combinations")); |
| 67 | + put("pass5", new Password("z8!E?7D$", "days", "20", "96 chars on 8 positions = 66 quintillion possible combinations")); |
| 68 | + put("pass6", new Password("My1stPassword!:Redd", "quintillion years", "364", "96 chars on 19 positions = 46 undecillion possible combinations")); |
| 69 | + }}; |
| 70 | + |
| 71 | + private class Password { |
| 72 | + |
| 73 | + String password; |
| 74 | + String timeUnit; |
| 75 | + String answer; |
| 76 | + private String explanation; |
| 77 | + |
| 78 | + public Password(String password, String timeUnit, String answer, String explanation) { |
| 79 | + this.password = password; |
| 80 | + this.timeUnit = timeUnit; |
| 81 | + this.answer = answer; |
| 82 | + this.explanation = explanation; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + private boolean checkSolution(WebSession s) throws ParameterNotFoundException { |
| 87 | + boolean allCorrect = true; |
| 88 | + for ( int i = 1; i <= passwords.size(); i++ ) { |
| 89 | + String key = "pass" + i; |
| 90 | + allCorrect = allCorrect && s.getParser().getStringParameter(key, "").equals(passwords.get(key).answer); |
| 91 | + } |
| 92 | + return allCorrect; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Description of the Method |
| 97 | + * |
| 98 | + * @param s |
| 99 | + * Description of the Parameter |
| 100 | + * @return Description of the Return Value |
| 101 | + */ |
| 102 | + protected Element createContent(WebSession s) |
| 103 | + { |
| 104 | + ElementContainer ec = new ElementContainer(); |
| 105 | + |
| 106 | + try |
| 107 | + { |
| 108 | + if (checkSolution(s)) |
| 109 | + { |
| 110 | + makeSuccess(s); |
| 111 | + ec.addElement(new BR()); |
| 112 | + ec.addElement(new StringElement("As a guideline not bound to a single solution.")); |
| 113 | + ec.addElement(new BR()); |
| 114 | + ec.addElement(new StringElement("Assuming the calculations per second 4 billion: ")); |
| 115 | + ec.addElement(new BR()); |
| 116 | + OL ol = new OL(); |
| 117 | + for ( Password password : passwords.values()) { |
| 118 | + ol.addElement(new LI(String.format("%s - %s %s (%s)", password.password, password.answer, password.timeUnit, password.explanation))); |
| 119 | + } |
| 120 | + ec.addElement(ol); |
| 121 | + } else |
| 122 | + { |
| 123 | + ec.addElement(new BR()); |
| 124 | + ec.addElement(new StringElement("How much time would a desktop PC take to crack these passwords?")); |
| 125 | + ec.addElement(new BR()); |
| 126 | + ec.addElement(new BR()); |
| 127 | + Table table = new Table(); |
| 128 | + for ( Entry<String, Password> entry : passwords.entrySet()) { |
| 129 | + TR tr = new TR(); |
| 130 | + TD td1 = new TD(); |
| 131 | + TD td2 = new TD(); |
| 132 | + Input input1 = new Input(Input.TEXT, entry.getKey(), ""); |
| 133 | + td1.addElement(new StringElement("Password = " + entry.getValue().password)); |
| 134 | + td1.setWidth("50%"); |
| 135 | + td2.addElement(input1); |
| 136 | + td2.addElement(new StringElement(" " + entry.getValue().timeUnit)); |
| 137 | + tr.addElement(td1); |
| 138 | + tr.addElement(td2); |
| 139 | + table.addElement(tr); |
| 140 | + } |
| 141 | + ec.addElement(table); |
| 142 | + ec.addElement(new BR()); |
| 143 | + ec.addElement(new BR()); |
| 144 | + Div div = new Div(); |
| 145 | + div.addAttribute("align", "center"); |
| 146 | + Element b = ECSFactory.makeButton("Go!"); |
| 147 | + div.addElement(b); |
| 148 | + ec.addElement(div); |
| 149 | + } |
| 150 | + } catch (Exception e) |
| 151 | + { |
| 152 | + s.setMessage("Error generating " + this.getClass().getName()); |
| 153 | + e.printStackTrace(); |
| 154 | + } |
| 155 | + |
| 156 | + |
| 157 | + return (ec); |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * Gets the hints attribute of the HelloScreen object |
| 162 | + * |
| 163 | + * @return The hints value |
| 164 | + */ |
| 165 | + public List<String> getHints(WebSession s) |
| 166 | + { |
| 167 | + List<String> hints = new ArrayList<String>(); |
| 168 | + hints.add("Copy the passwords into the code checker."); |
| 169 | + return hints; |
| 170 | + } |
| 171 | + |
| 172 | + /** |
| 173 | + * Gets the ranking attribute of the HelloScreen object |
| 174 | + * |
| 175 | + * @return The ranking value |
| 176 | + */ |
| 177 | + private final static Integer DEFAULT_RANKING = new Integer(6); |
| 178 | + |
| 179 | + protected Integer getDefaultRanking() |
| 180 | + { |
| 181 | + return DEFAULT_RANKING; |
| 182 | + } |
| 183 | + |
| 184 | + protected Category getDefaultCategory() |
| 185 | + { |
| 186 | + return Category.AUTHENTICATION; |
| 187 | + } |
| 188 | + |
| 189 | + public String getInstructions(WebSession s) |
| 190 | + { |
| 191 | + String instructions = "The accounts of your web application are only as save as the passwords. " |
| 192 | + + "For this exercise, your job is to test several passwords on <a href=\"https://howsecureismypassword.net\" target=\"_blank\">https://howsecureismypassword.net</a>. " |
| 193 | + + " You must test all 6 passwords at the same time...<br>" |
| 194 | + + "<b> On your applications you should set good password requirements! </b>"; |
| 195 | + return (instructions); |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * Gets the title attribute of the HelloScreen object |
| 200 | + * |
| 201 | + * @return The title value |
| 202 | + */ |
| 203 | + public String getTitle() |
| 204 | + { |
| 205 | + return ("Password Strength"); |
| 206 | + } |
| 207 | + |
| 208 | + public Element getCredits() |
| 209 | + { |
| 210 | + return super.getCustomCredits("Created by: Reto Lippuner, Marcel Wirth", new StringElement("")); |
| 211 | + } |
211 | 212 | }
|
0 commit comments