Skip to content

Latest commit

 

History

History
48 lines (28 loc) · 882 Bytes

Not_very_secure.md

File metadata and controls

48 lines (28 loc) · 882 Bytes

CodeWars Python Solutions


Not very secure

In this example you have to validate if a user input string is alphanumeric. The given string is not nil/null/NULL/None, so you don't have to check that.

The string has the following conditions to be alphanumeric:

  • At least one character ("" is not valid)
  • Allowed characters are uppercase / lowercase latin letters and digits from 0 to 9
  • No whitespaces / underscore

Given Code

def alphanumeric(password):
    pass

Solution 1

def alphanumeric(password):
    return " " not in password and len([c for c in password if c.isdigit() or c.isalpha()]) == len(password) and len(password) > 0

Solution 2

def alphanumeric(string):
    return string.isalnum()

See on CodeWars.com