<s> """<STR_LIT>""" <EOL> import hashlib <EOL> import M2Crypto <EOL> import os <EOL> import SOAPpy <EOL> import string <EOL> import sys <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) ) <EOL> import appscale_info <EOL> import constants <EOL> def random_password ( length = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> chars = string . ascii_uppercase + string . digits + string . ascii_lowercase <EOL> password = '<STR_LIT>' <EOL> for i in range ( length ) : <EOL> password += chars [ ord ( M2Crypto . m2 . rand_bytes ( <NUM_LIT:1> ) ) % len ( chars ) ] <EOL> return password <EOL> def get_soap_accessor ( ) : <EOL> """<STR_LIT>""" <EOL> db_ip = appscale_info . get_db_master_ip ( ) <EOL> bindport = constants . UA_SERVER_PORT <EOL> return SOAPpy . SOAPProxy ( "<STR_LIT>" . format ( db_ip , bindport ) ) <EOL> def create_new_user ( server , email , password ) : <EOL> """<STR_LIT>""" <EOL> secret = appscale_info . get_secret ( ) <EOL> ret = server . commit_new_user ( email , password , "<STR_LIT:user>" , secret ) <EOL> return not ret . startswith ( "<STR_LIT>" ) <EOL> def does_user_exist ( email , server ) : <EOL> """<STR_LIT>""" <EOL> secret = appscale_info . get_secret ( ) <EOL> return server . does_user_exist ( email , secret ) == "<STR_LIT:true>" <EOL> def usage ( ) : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> def is_valid_email ( email ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT:@>" in email and "<STR_LIT:.>" in email <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> total = len ( sys . argv ) <EOL> if total != <NUM_LIT:2> : <EOL> usage ( ) <EOL> exit ( <NUM_LIT:1> ) <EOL> email = sys . argv [ <NUM_LIT:1> ] <EOL> if not is_valid_email ( email ) : <EOL> print "<STR_LIT>" <EOL> exit ( <NUM_LIT:1> ) <EOL> new_password = random_password ( ) <EOL> server = get_soap_accessor ( ) <EOL> if does_user_exist ( email , server ) : <EOL> print "<STR_LIT>" <EOL> exit ( <NUM_LIT:1> ) <EOL> print "<STR_LIT>" <EOL> hash_password = hashlib . sha1 ( email + new_password ) . hexdigest ( ) <EOL> create_new_user ( server , email , hash_password ) <EOL> print "<STR_LIT>" . format ( email , new_password ) <EOL> print "<STR_LIT>" </s>
