<div dir="ltr">al posto della list comprehesion suggerisco un bel `any` -> `if any(errors.values())`. any è una sorta di or aggreggato (reduce con or) invece `all` è una sorta di `and` aggreggato. ( E sono utili quando uno deve usare un sacco di or o di and)</div><br><div class="gmail_quote"><div dir="ltr">Il giorno lun 5 mar 2018 alle ore 05:00 Karim <<a href="mailto:lemieliste@gmail.com">lemieliste@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2018-03-05 10:05 GMT+11:00 Silvestro De Santis <span dir="ltr"><<a href="mailto:silvestro.desantis@gmail.com" target="_blank">silvestro.desantis@gmail.com</a>></span>:<br></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF">
<p>Sera lista in attesa dei risultati elettorali stavo provando le
regex con python, ho fatto una semplice funzione che determina se
la </p></div></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF"><div class="gmail_default" style="font-family:verdana,sans-serif;display:inline">[...]</div><p></p></div></blockquote></div><div><br></div><div><div class="gmail_default" style="font-family:verdana,sans-serif">L'errore e' negli and, dovevano essere degli or.</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Dato che la funzione mi servira' in futuro per altri scopi, mi sono preso la briga di implementarla. Io l'avrei fatta cosi':</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default"><div class="gmail_default"><font face="verdana, sans-serif">import re</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif">def validate_password(password):</font></div><div class="gmail_default"><font face="verdana, sans-serif"> """Validate the password based on "some" strenght rules</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif"> :param str password: The password to validate</font></div><div class="gmail_default"><font face="verdana, sans-serif"> :returns: a tuple with the validation result and the errors details if the</font></div><div class="gmail_default"><font face="verdana, sans-serif"> validation fails</font></div><div class="gmail_default"><font face="verdana, sans-serif"> :rtype: (True, None) or (False, dict)</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif"> .. todo:</font></div><div class="gmail_default"><font face="verdana, sans-serif"> - The symbols check is not correct</font></div><div class="gmail_default"><font face="verdana, sans-serif"> """</font></div><div class="gmail_default"><font face="verdana, sans-serif"> lenght = len(password)</font></div><div class="gmail_default"><font face="verdana, sans-serif"> digits = re.compile(r'\d+')</font></div><div class="gmail_default"><font face="verdana, sans-serif"> uppers = re.compile(r'[A-Z]+')</font></div><div class="gmail_default"><font face="verdana, sans-serif"> lowers = re.compile(r'[a-z]+')</font></div><div class="gmail_default"><font face="verdana, sans-serif"> symbols = re.compile(r'\\|-|@|_|\?')</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif"> errors = {</font></div><div class="gmail_default"><font face="verdana, sans-serif"> 'lowers': False if lowers.search(password) else True,</font></div><div class="gmail_default"><font face="verdana, sans-serif"> 'lenght': bool(lenght < 8),</font></div><div class="gmail_default"><font face="verdana, sans-serif"> 'digits': False if digits.search(password) else True,</font></div><div class="gmail_default"><font face="verdana, sans-serif"> 'symbols': False if symbols.search(password) else True,</font></div><div class="gmail_default"><font face="verdana, sans-serif"> 'uppers': False if uppers.search(password) else True,</font></div><div class="gmail_default"><font face="verdana, sans-serif"> }</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif"> if [error for error in errors.values() if error]:</font></div><div class="gmail_default"><font face="verdana, sans-serif"> return False, errors</font></div><div class="gmail_default"><font face="verdana, sans-serif"> else:</font></div><div class="gmail_default"><font face="verdana, sans-serif"> return True, None</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif">if __name__ == '__main__':</font></div><div class="gmail_default"><font face="verdana, sans-serif"> pwd = input('Inserisci password: ')</font></div><div class="gmail_default"><font face="verdana, sans-serif"> robust, errors = validate_password(pwd)</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif"> if not robust:</font></div><div class="gmail_default"><font face="verdana, sans-serif"> print('Errori trovati: %s' % errors.keys())</font></div><div class="gmail_default"><font face="verdana, sans-serif"> else:</font></div><div class="gmail_default"><font face="verdana, sans-serif"> print('Password robusta')</font></div><div style="font-family:verdana,sans-serif"><br></div></div><br></div><div><div class="gmail_default" style="font-family:verdana,sans-serif">Ciao</div><br></div></div></div><div dir="ltr"><div class="gmail_extra"><div><br></div>-- <br><div class="m_1719226321098479600gmail_signature"><div dir="ltr">Karim N. Gorjux<br></div></div>
</div></div>
_______________________________________________<br>
Python mailing list<br>
<a href="mailto:Python@lists.python.it" target="_blank">Python@lists.python.it</a><br>
<a href="https://lists.python.it/mailman/listinfo/python" rel="noreferrer" target="_blank">https://lists.python.it/mailman/listinfo/python</a><br>
</blockquote></div>