def launchStoreRequest(): #get the ajaxed info if request.method == "POST": #create objects star = Star(c) slack = Slack() email = Mailer() #grab the info from ajax request info = request.get_json() #create the star ID using the instagram info['star']['id'] = star.getID(info['star']['instagram'].lower()) #hash the password info['star']['password'] = hash_password(info['star']['password'], salt) star.createProfile(info) #create a star profile star_info = star.createStore(info) #create a new store for the star #star.giftCoin(info['star']['email']) #gift a coin #send alert to Fandemic team via slack slack.sendStoreCreatedAlert(info) #send confirmation to star via email email.sendStoreConfirmation(info,star_info['img']['profile']) return '';
def post(self): app.logger.debug(request.remote_addr) data = request.data data_dict = json.loads(data) username = data_dict['username'] my_password = data_dict['password'] if my_password == "": return redirect(url_for('login')), 400 encrypt_pass = password.hash_password(my_password) user_struct = { 'username': username, 'password': encrypt_pass, 'ip': request.remote_addr, 'token': None } app.logger.debug("USER DATA BASE: ") _users = db.user_db.find() total = 1 for user in _users: total += 1 if username == user['username']: return "That name has already been taken! Try again.", 401 db.user_db.insert_one(user_struct) ret_json = {'username': username, 'password': encrypt_pass} return ret_json, 201, { 'Location': 'http://127.0.0.1:5000/api/user_db/' + str(total) }
def registerUser(): un = request.args.get('username', default="", type=str) pwRAW = request.args.get('password', default="", type=str) data = usersCollection.find() for datum in data: if datum['username'] == un: result = { "location": "", "username": "", "password": "", "message": "400: Username '" + un + "' is already taken." } return flask.jsonify(result=result) #, 400 pw = password.hash_password(pwRAW) usersCollection.insert({"username": un, "password": pw}) ids = [] data = usersCollection.find() for datum in data: ids.append(datum['_id']) location = str(ids[len(ids) - 1]) token = generate_auth_token(600, location) session['token'] = token result = { "location": location, "username": un, "password": pw, "message": "" } return flask.jsonify(result=result), 201
def register(): form = RegisterationForm() username = request.form.get('username') password = request.form.get('password') if request.method == 'POST' and form.validate(): user = usersdb.users.find_one({'username': username}) if user == None: #hash the password then get rid of password hVal = hash_password(password) password = '' addUser = {'username': username, 'password': hVal} #adds new user to database addedUser = usersdb.users.insert_one(addUser) user_id = str(addedUser.inserted_id) return jsonify({ 'username': addUser['username'], 'location': user_id }), 201 else: flash("User already exists, please try a different username"), 400 return render_template('register.html', form=form), 400
def registration(message=''): if request.method == 'POST': username = request.form['regUserName'] usr_password = request.form['regPass'] is_user = queries.check_username(username) if is_user: message = 'Username taken, please choose another.' return render_template('registration.html', message=message) else: hashed_password = password.hash_password(usr_password) queries.create_user(username, hashed_password) return redirect(url_for('index')) else: return render_template('registration.html', message=message)
def register(): form = RegistrationForm() global x if request.method == 'POST' and form.validate(): user = User(form.username.data, u'{}'.format(x)) entry = { '_id': x, 'username': form.username.data, 'password': hash_password(form.password.data) } dbpass.userdb.insert_one(entry) return flask.redirect('http://0.0.0.0:5001/users/{}'.format( '{}'.format(x))) return render_template('registration.html', form=form)
def reset_password(): user = input("Username:$$$>") emails = cursor.execute(TAKE_EMAIL, [user, ]) email = '' for e in emails: email = e['email'] new_pass = generate_new_pass() msg = "Your new password is {0}".format(new_pass) new_pass = hash_password(new_pass) change_pass(new_pass, user) send_mail(email, msg)
def post(self): user = request.form['username'] passw = request.form['password'] _items = db_user.user.find({"user": user}) items = [item for item in _items] if (user == '' or passw == ''): return "Wrong user or password", 400 elif (items != []): return "username already exist", 400 else: _items2 = db_user.user.find() items2 = [item for item in _items2] pwd = password.hash_password(passw) values = {"location": len(items2), "user": user, "password": pwd} db_user.user.insert_one(values) return 'register success'
def _new_user(): my_password = request.form['password'] if my_password == "": return redirect(url_for('login')), 400 encrypt_pass = password.hash_password(my_password) user_struct = { 'username': request.form['username'], 'password': encrypt_pass, 'ip': None, 'token': None } db.user_db.insert_one(user_struct) app.logger.debug("USER DATA BASE: ") _items = db.user_db.find() for item in _items: app.logger.debug(item) return redirect(url_for('login')), 201
def post(self): # Get fields parser = reqparse.RequestParser() parser.add_argument('username', required=True, help="username cannot be blank!") parser.add_argument('password', required=True, help="password cannot be blank") args = parser.parse_args() username = args['username'] password = args['password'] # Check for empty arguments if username == None or password == None: return {"client error": "bad request"}, 400 # Check for duplicate username if collection.users.find_one({"username": username}) != None: return {"client error": "username already exists"}, 418 # Hash password hashedpass = hash_password(password) # throw away password data password = None # Insert into database post_id = collection.users.insert_one({ "username": username, "password": hashedpass }) userId = str(post_id.inserted_id) # Success return { "success": "created", "username": username, "location": userId }, 201
def register(): form = LoginForm() user = form.username.data app.logger.debug("user: {}".format(user)) if form.validate_on_submit(): if Userdb.todouserdb.find({"username": user}, {}).count() == 0: pas = hash_password(form.password.data) id = Userdb.todouserdb.count({}) item_doc = { 'id': id, 'username': user, 'password': pas, 'token': '' } Userdb.todouserdb.insert_one(item_doc) one = Userdb.todouserdb.find_one({"username": user}) app.logger.debug("userob: {}".format(one['id'])) return redirect(url_for("login")) else: flash("that username is already taken") one = Userdb.todouserdb.find_one({"username": user}) app.logger.debug("userob: {}".format(one)) return render_template('register.html', title='Register', form=form)
def signup(): form = SignupForm() if form.validate_on_submit(): username = form.username.data password = form.password.data # Check for empty arguments if username == None or password == None: flask.flash("empty fields!") return render_template('signup.html', form=form) # Check for duplicate username if collection.users.find_one({"username": username}) != None: flask.flash("username already exists") return render_template('signup.html', form=form) # Hash password hashedpass = hash_password(password) # throw away password data password = None # Insert into database post_id = collection.users.insert_one({ "username": username, "password": hashedpass }) userId = str(post_id.inserted_id) # Success return flask.jsonify({ "success": "created", "username": username, "location": userId }), 200 return render_template('signup.html', form=form)
def generate_fake_users(conn): names = [] with open(getpath("random_names.txt")) as f: names = [name.strip() for name in f] for i in range(len(names)): fname, lname = random.sample(names, 2) username = (fname[0] + lname).lower() email = "{}{:03}@yoloteamfour.com".format(username, random.randint(0, 100)) salt = generate_salt() password = username[::-1] password = hash_password(password, salt) dob = "{:04}-{:02}-{:02}".format(random.randint(1970, 2000), random.randint(1, 12), random.randint(1, 28)) try: conn.execute("""INSERT INTO tbl_users (fname, lname, username, email, password, salt, dob) VALUES (?, ?, ?, ?, ?, ?, strftime('%s', ?))""", (fname, lname, username, email, password, salt, dob)) except sqlite3.IntegrityError: pass conn.commit()
def __init__(self, username="", password="", salt=""): self._id = -1 self.username = username self._hashed_password = hash_password(password, salt)
def get_hashed_password(plain_text_password): return hash_password(plain_text_password)
def __init__(self, username, password, authenticated=True): self.username = username self.password = p.hash_password(password) self.authenticated = authenticated #add password verify
def partnersForm(): companyname = request.form['companyname'] companywebsite = request.form['companywebsite'] companyemail = request.form['email'] username = request.form['username'] password = request.form['password'] hashed = hash_password(password, salt) #build dictionary userProfile = {} userProfile['username'] = username.lower() userProfile['hashed_pw'] = hashed userProfile['system'] = 'partners' userProfile['bio'] = {} userProfile['bio']['company_id'] = companyname.replace(" ","-").lower() userProfile['bio']['company_name'] = companyname userProfile['bio']['short_story'] = '' userProfile['bio']['contact_name'] = '' userProfile['bio']['website'] = companywebsite userProfile['bio']['email'] = companyemail userProfile['bio']['phone'] = '' userProfile['bio']['logo_url'] = '' userProfile['bio']['approved'] = False userProfile['bio']['address'] = {} userProfile['bio']['address']['street'] = '' userProfile['bio']['address']['city'] = '' userProfile['bio']['address']['state'] = '' userProfile['bio']['address']['zip'] = '' userProfile['bio']['address']['country'] = '' db.profiles.insert_one(userProfile) toaddr = [companyemail] subject = "Thank you for letting us work with " + companyname + "!" html = """ Hey There! <br><br> My name is Sarah and I'll be your advisor to help walk you through the Fandemic experience for """+companyname+"""! <br><br> When you get a chance, please <a href="http://admin.fandemic.co"> sign in here </a> using the username ("""+username+""") and password you provided, begin filling out your profile, and upload all your best products/variations. <br><br> Please, let me know if you have ANY questions at all (there are no silly questions)! <br><br> Thanks so much, <br> Sarah """ if MODE == 'live': email = Mailer() email.send(toaddr,subject,html) slack = Slack() slack.sendPartnerSignupAlert(userProfile) #return redirect("/partners", code=302) return ''
def sign_up(password1, password2): if password1 != password2: raise Exception("Password Mismatch") hashed_pass = hash_password(password1) keys = make_account() #keys[0] -> public key keys[1] -> private key return hashed_pass, keys
players[id]['exAttribute0'] = 1000 break if players[id]['exAttribute0'] == 1002: players[id]['idleStart'] = int(time.time()) mud.send_message(id, "<f220>\nOk, got that.") players[id]['exAttribute2'] = command # Load the player template from a file with open(str(Config.get('Players', 'Location')) + "/player.template", "r") as read_file: template = commentjson.load(read_file) # Make required changes to template before saving again into <Name>.player template['name'] = players[id]['exAttribute1'] template['pwd'] = hash_password(players[id]['exAttribute2']) # Save template into a new player file # print(template) with open(str(Config.get('Players', 'Location')) + "/" + template['name'] + ".player", 'w') as fp: commentjson.dump(template, fp) # Reload PlayersDB to include this newly created player playersDB = loadPlayersDB() players[id]['exAttribute0'] = None mud.send_message(id, '<f220>Your character has now been created, you can log in using credentials you have provided.\n') # mud.send_message(id, '<f15>What is your username?') mud.send_message(id, "<f15>What is your username?<r>\n<f246>Type '<f253>new<r><f246>' to create a character.") log("Client ID: " + str(id) + " has completed character creation (" + template['name'] + ").", "info") break
def set_password(self, password, salt=""): self._hashed_password = hash_password(password, salt)