|
1 | 1 | using MissionPlanner.Mavlink;
|
2 | 2 | using MissionPlanner.Utilities;
|
3 | 3 | using System;
|
| 4 | +using System.Linq; |
4 | 5 | using System.Windows.Forms;
|
5 | 6 |
|
6 | 7 | namespace MissionPlanner.Controls
|
@@ -61,10 +62,50 @@ private void but_add_Click(object sender, EventArgs e)
|
61 | 62 |
|
62 | 63 | string pass = "";
|
63 | 64 |
|
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) |
65 | 66 | {
|
66 | 67 | 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 | + } |
68 | 109 | MAVAuthKeys.AddKey(dataGridView1[FName.Index, row].Value.ToString(), input);
|
69 | 110 | }
|
70 | 111 |
|
|
0 commit comments