Skip to content

Commit f836822

Browse files
committed
AuthKeys: add complexity score
1 parent 6050a04 commit f836822

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

Controls/AuthKeys.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using MissionPlanner.Mavlink;
22
using MissionPlanner.Utilities;
33
using System;
4+
using System.Linq;
45
using System.Windows.Forms;
56

67
namespace MissionPlanner.Controls
@@ -61,10 +62,50 @@ private void but_add_Click(object sender, EventArgs e)
6162

6263
string pass = "";
6364

64-
if (InputBox.Show("Input Seed", "Please enter your pass phrase", ref pass) == DialogResult.OK)
65+
if (InputBox.Show("Input Seed", "Please enter your pass phrase/sentence\nNumbers, Lower Case, Upper Case, Symbols, and 12+ chars long using atleast 2 of each", ref pass) == DialogResult.OK)
6566
{
6667
var input = InputBox.value;
67-
68+
{
69+
var n = 0;
70+
int score = 0;
71+
var len = input.Length;
72+
73+
// chars
74+
score += len * 4;
75+
// upper
76+
n = input.Count(c => char.IsUpper(c));
77+
if(n > 0)
78+
score += (len - n) * 2;
79+
// lower
80+
n = input.Count(c => char.IsLower(c));
81+
if (n > 0)
82+
score += (len - n) * 2;
83+
//number
84+
n = input.Count(c => char.IsNumber(c));
85+
if (n > 0)
86+
score += n * 4;
87+
//symbols
88+
n = input.Count(c => char.IsSymbol(c) || char.IsPunctuation(c));
89+
if (n > 0)
90+
score += n * 6;
91+
//middle number or symbol
92+
n = input.Skip(1).Take(len - 2).Count(c => char.IsSymbol(c) || char.IsPunctuation(c) || char.IsNumber(c));
93+
if (n > 0)
94+
score += n * 2;
95+
// letters only
96+
n = input.Count(c => char.IsLetter(c));
97+
score += len == n ? -len : 0;
98+
// numbers only
99+
n = input.Count(c => char.IsNumber(c));
100+
score += len == n ? -len : 0;
101+
102+
if(score <= 40)
103+
CustomMessageBox.Show("Password Strength: " + score + " WEAK - it will be added, but please pick a better password");
104+
else if (score <= 60)
105+
CustomMessageBox.Show("Password Strength: " + score + " Good");
106+
else if (score > 60)
107+
CustomMessageBox.Show("Password Strength: " + score + " Strong");
108+
}
68109
MAVAuthKeys.AddKey(dataGridView1[FName.Index, row].Value.ToString(), input);
69110
}
70111

0 commit comments

Comments
 (0)