@@ -33,7 +33,6 @@ LocalComponents.Page {
3333 backButtonText: i18n.tr("Cancel")
3434
3535 property alias password: passwordField.text
36− readonly property int passwordScore: scorePassword(password)
3736 property bool confirmPhase: false
3837
3938 // If we are entering this page, clear any saved password and get focus
@@ -71,39 +70,10 @@ LocalComponents.Page {
7170 if (!!text) {
7271 infoLabel.text = text
7372 } else {
74− infoLabel.text = i18n.tr("Enter at least 4 characters")
73+ infoLabel.text = i18n.tr("Enter at least 6 characters")
7574 }
7675 }
7776
78− function scorePassword(pass) {
79− var score = 0;
80− if (!pass)
81− return score;
82−
83− // award every unique letter until 5 repetitions
84− var letters = Object();
85− for (var i=0; i<pass.length; i++) {
86− letters[pass[i]] = (letters[pass[i]] || 0) + 1;
87− score += 5.0 / letters[pass[i]];
88− }
89−
90− // bonus points for mixing it up
91− var variations = {
92− digits: /\d/.test(pass),
93− lower: /[a-z]/.test(pass),
94− upper: /[A-Z]/.test(pass),
95− nonWords: /\W/.test(pass),
96− }
97−
98− var variationCount = 0;
99− for (var check in variations) {
100− variationCount += (variations[check] === true) ? 1 : 0;
101− }
102− score += (variationCount - 1) * 10;
103−
104− return parseInt(score);
105− }
106−
10777 Item {
10878 id: column
10979 anchors.fill: content
@@ -139,59 +109,21 @@ LocalComponents.Page {
139109 }
140110 }
141111
142− Rectangle {
143− id: passwordStrengthMeter
144− anchors {
145− left: parent.left
146− right: parent.right
147− top: passwordField.bottom
148− topMargin: units.gu(1)
149− }
150− width: parent.width
151− height: units.gu(1)
152− color: {
153− if (passwordScore > 80)
154− return "green";
155− if (passwordScore > 60)
156− return "orange";
157− if (passwordScore >= 30)
158− return "red";
159−
160− return "red";
161− }
162− visible: password.length > 0
163− }
164−
165− Label {
166− id: passwordStrengthInfo
167− anchors {
168− left: parent.left
169− right: parent.right
170− top: passwordStrengthMeter.bottom
171− topMargin: units.gu(1)
172− }
173− wrapMode: Text.Wrap
174− text: {
175− if (passwordScore > 80)
176− return i18n.tr("Strong password");
177− else if (passwordScore > 60)
178− return i18n.tr("Medium password")
179− if (passwordScore >= 30)
180− return i18n.tr("Weak password");
181−
182− return i18n.tr("Very weak password");
183− }
184− color: "#888888"
185− fontSize: "small"
186− font.weight: Font.Light
187− visible: password.length > 0
112+ // password meter
113+ LocalComponents.PasswordMeter {
114+ id: passMeter
115+ anchors.left: parent.left
116+ anchors.right: parent.right
117+ anchors.top: passwordField.bottom
118+ anchors.topMargin: units.gu(1)
119+ password: passwordField.text
188120 }
189121 }
190122
191123 Component {
192124 id: forwardButton
193125 LocalComponents.StackButton {
194− enabled: confirmPhase ? password === root.password : password.length >= 4 // TODO set more sensible restrictions for the length?
126+ enabled: confirmPhase ? password === root.password : password.length > 5 // TODO set more sensible restrictions for the length?
195127 text: i18n.tr("OK")
196128 onClicked: {
197129 if (confirmPhase) {