예제 #1
0
 def post(self):
     form = RegisterForm(self.request.POST)
     if form.validate():
         # Submit the query in the datastore
         email = db.GqlQuery("SELECT * FROM User WHERE email='%s'"
                             % form.email.data)
         username = db.GqlQuery("SELECT * FROM User WHERE username='******'"
                                % form.username.data)
         username, email = username.get(), email.get()
         # if there is no record in the datastore with the provided data
         # create a new user.
         if email is None and username is None:
             hashedPass = bcrypt.hashpw(form.passwd.data, bcrypt.gensalt(2))
             newuser = User(name=form.name.data,
                            surname=form.surname.data,
                            email=form.email.data,
                            username=form.username.data,
                            password=hashedPass)
             newuser.put()
             # Create the session for the new user
             self.session['username'] = form.username.data
             self.redirect("/")
             # todo: refactor the if to catch both mailError
             # and usernameError at the same time.
         elif email is not None:
             self.render("register.html", form=form,
                         mailError="This Mail Is Already Registered",
                         username=self.session.get("username"))
         elif username is not None:
             self.render("register.html", form=form,
                         usernameError="This Username Is Taken :-(",
                         username=self.session.get("username"))
     else:
         self.render("register.html", form=form,
                     username=self.session.get("username"))
예제 #2
0
def hash_password(password):
    """
    Return the hashed equivalent of a password
    :param password: input password
    :return: equivalent encrypted value using the bcrypt algorithm
    """
    if password:
        return bcrypt.hashpw(password, bcrypt.gensalt())
예제 #3
0
def register():

    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        pwhash = bcrypt.hashpw(password, bcrypt.gensalt())
        u = User()
        u.register(username, pwhash)
        session['username'] = username
        return redirect(url_for('frontend.index'))

    else:
        return render_template('register.html')
예제 #4
0
    def post(self):
        username = self.request.params['username']
        password = self.request.params['password']
        user = ModelUser.keyfor(username).get()
        if user:
            params = urllib.urlencode(
                {"error": "user {} exists".format(cgi.escape(username))})
            self.redirect("/register?" + params)
            return

        user = ModelUser(key=ModelUser.keyfor(username),
                         username=username,
                         pwhash=bcrypt.hashpw(password, bcrypt.gensalt(5)))
        user.put()
        create_session(self.response, username)
        self.redirect('/')
예제 #5
0
    def generate_password_hash(self, password, rounds=None):
        '''Generates a password hash using bcrypt. Specifying `rounds` 
        sets the log_rounds parameter of `bcrypt.gensalt()` which determines 
        the complexity of the salt. 12 is the default value.
        
        Example usage of :class:`generate_password_hash` might look something 
        like this::
            
            pw_hash = bcrypt.generate_password_hash('secret', 10)
        
        :param password: The password to be hashed.
        :param rounds: The optional number of rounds.
        '''

        if not password:
            raise ValueError('Password must be non-empty.')

        if rounds is None:
            rounds = self._log_rounds
        if isinstance(password, unicode):
            password = password.encode('u8')
        password = str(password)
        return bcrypt.hashpw(password, bcrypt.gensalt(rounds))
예제 #6
0
 def generate_password_hash(self, password, rounds=None):
     '''Generates a password hash using bcrypt. Specifying `rounds` 
     sets the log_rounds parameter of `bcrypt.gensalt()` which determines 
     the complexity of the salt. 12 is the default value.
     
     Example usage of :class:`generate_password_hash` might look something 
     like this::
         
         pw_hash = bcrypt.generate_password_hash('secret', 10)
     
     :param password: The password to be hashed.
     :param rounds: The optional number of rounds.
     '''
     
     if not password:
         raise ValueError('Password must be non-empty.')
     
     if rounds is None:
         rounds = self._log_rounds
     if isinstance(password, unicode):
         password = password.encode('u8')
     password = str(password)
     return bcrypt.hashpw(password, bcrypt.gensalt(rounds))
예제 #7
0
파일: main.py 프로젝트: armedjack/armedjack
def make_hash(*args): # создание хеша из полученных аргументов
	line_for_hashing = ""
	for arg in args:
		line_for_hashing += str(arg)
	return bcrypt.hashpw(line_for_hashing, bcrypt.gensalt())
예제 #8
0
def make_pw_hash(email, pw, salt = None): # Course function
    if not salt:
        salt = bcrypt.gensalt()
    h = bcrypt.hashpw(email + pw, salt)
    return( "%s|%s" % (salt, h))
예제 #9
0
def make_secure_val(val, secret, salt=None):
    if not salt:
        salt = bcrypt.gensalt()
    h = bcrypt.hashpw(val + secret, salt)
    return ('%s|%s|%s' % (val, h, salt))
예제 #10
0
def hash_str(s, salt=None):
    if not salt:
        salt = bcrypt.gensalt()
    h = bcrypt.hashpw(s, salt)
    return ("%s|%s|%s" % (s, h, salt))
예제 #11
0
def hash_pwd(pwd):
    new_pwd = bcrypt.hashpw(pwd, bcrypt.gensalt(6))
    pwd = None
    return new_pwd
예제 #12
0
 def make_hash(self, name, pw):
     return bcrypt.hashpw(pw + name, bcrypt.gensalt())
예제 #13
0
	def make_hash (self, name, pw):    	     		
 		return bcrypt.hashpw(pw+name, bcrypt.gensalt())