Created
February 28, 2014 22:05
-
-
Save offlinemark/9280984 to your computer and use it in GitHub Desktop.
Using a positive security model (whitelist), sanitize username input for a login form, for example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def is_clean(username): | |
# usernames are allowed to have a-zA-Z0-9_. | |
# nothing else | |
if re.search('[^\w.]', username): | |
return False | |
else: | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment