2018-03-05 10:05 GMT+11:00 Silvestro De Santis <silvestro.desan...@gmail.com >:
> Sera lista in attesa dei risultati elettorali stavo provando le regex con > python, ho fatto una semplice funzione che determina se la > [...] > > L'errore e' negli and, dovevano essere degli or. Dato che la funzione mi servira' in futuro per altri scopi, mi sono preso la briga di implementarla. Io l'avrei fatta cosi': import re def validate_password(password): """Validate the password based on "some" strenght rules :param str password: The password to validate :returns: a tuple with the validation result and the errors details if the validation fails :rtype: (True, None) or (False, dict) .. todo: - The symbols check is not correct """ lenght = len(password) digits = re.compile(r'\d+') uppers = re.compile(r'[A-Z]+') lowers = re.compile(r'[a-z]+') symbols = re.compile(r'\\|-|@|_|\?') errors = { 'lowers': False if lowers.search(password) else True, 'lenght': bool(lenght < 8), 'digits': False if digits.search(password) else True, 'symbols': False if symbols.search(password) else True, 'uppers': False if uppers.search(password) else True, } if [error for error in errors.values() if error]: return False, errors else: return True, None if __name__ == '__main__': pwd = input('Inserisci password: ') robust, errors = validate_password(pwd) if not robust: print('Errori trovati: %s' % errors.keys()) else: print('Password robusta') Ciao -- Karim N. Gorjux
_______________________________________________ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python