Skip to content

Instantly share code, notes, and snippets.

@offlinemark
Created February 28, 2014 22:05
Show Gist options
  • Save offlinemark/9280984 to your computer and use it in GitHub Desktop.
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.
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