Archivio Posts |
Anno 2017
Anno 2015
Anno 2014
Anno 2013
Anno 2012
Anno 2010
Anno 2008
Anno 2007
|
|
[RegEx In Practice] - Controllare la complessità di una password
Richiesta: "devo controllare che una password sia almeno lunga 6 caratteri e al suo interno ci sia almeno 1 numero, una lettera maiuscola e una minuscola, hai una regex per questo?"
Risposta: "assolutamente si, è quello che ci vuole!"
Eccola:
\A(?=[-_a-zA-Z0-9]*?[A-Z])(?=[-_a-zA-Z0-9]*?[a-z])(?=[-_a-zA-Z0-9]*?[0-9])\S{6,}\z
Descrizione della regular expression (uso un software, RegexBuddy, non sono così bravo, ed è in inglese, non vi faccio la traduzione! ):
- Assert position at the start of the string
- Assert that the regex below can be matched, starting at this position (positive lookahead)
- Match a single character present in the list below
- Between zero and unlimited times, as few times as possible, expanding as needed (lazy)
- One of the characters "-_"
- A character in the range between "a" and "z"
- A character in the range between "A" and "Z"
- A character in the range between "0" and "9"
- Match a single character in the range between "A" and "Z"
- Assert that the regex below can be matched, starting at this position (positive lookahead)
- Match a single character present in the list below
- Between zero and unlimited times, as few times as possible, expanding as needed (lazy)
- One of the characters "-_"
- A character in the range between "a" and "z"
- A character in the range between "A" and "Z"
- A character in the range between "0" and "9"
- Match a single character in the range between "a" and "z"
- Assert that the regex below can be matched, starting at this position (positive lookahead)
- Match a single character present in the list below
- Between zero and unlimited times, as few times as possible, expanding as needed (lazy)
- One of the characters "-_"
- A character in the range between "a" and "z"
- A character in the range between "A" and "Z"
- A character in the range between "0" and "9"
- Match a single character in the range between "0" and "9"
- Match a single character that is a "non-whitespace character"
- Between 6 and unlimited times, as many times as possible, giving back as needed (greedy)
- Assert position at the very end of the string
Codice C#:
void Main() { string inputString = "asd2Df"; bool foundMatch = false; foundMatch = Regex.IsMatch(inputString, "\\A(?=[-_a-zA-Z0-9]*?[A-Z])(?=[-_a-zA-Z0-9]*?[a-z])(?=[-_a-zA-Z0-9]*?[0-9])\\S{6,}\\z"); Console.WriteLine(foundMatch); inputString = "asdjDf"; foundMatch = false; foundMatch = Regex.IsMatch(inputString, "\\A(?=[-_a-zA-Z0-9]*?[A-Z])(?=[-_a-zA-Z0-9]*?[a-z])(?=[-_a-zA-Z0-9]*?[0-9])\\S{6,}\\z"); Console.WriteLine(foundMatch); }
Ciao!
mercoledì, 20 mar 2013 Ore. 14.48
|
Calendario |
| l | m | m | g | v | s | d |
---|
30 | 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 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|
Statistiche |
- Views Home Page: 85.030
- Views Posts: 81.877
- Views Gallerie: 0
- n° Posts: 31
- n° Commenti: 18
|
|