示例#1
0
def login():
    error = None
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        if not username:
            error = 'empty username'
        elif not password:
            error = 'empty password'
        else:
            cur = g.db.execute(
                "SELECT username,password FROM accounts WHERE username=?",
                (username, ))
            row = cur.fetchone()
            if not row:
                error = 'user not found'
            else:
                p_hash = row[1]
                print 'login,username='******'password='******'hash=', p_hash
                if utils.check_hash(username, app.config['SECRET_KEY'],
                                    password, p_hash):
                    session['logged_in'] = True
                    session['logged_user'] = request.form['username']
                    flash('You were logged in')
                    return redirect(url_for('show_entries'))
                else:
                    error = 'username and password not match'
    return render_template('login.html', error=error)
示例#2
0
def check_hash():
    doc_hash = request.args.get('hash')
    if utils.check_hash(SEARCH_API, doc_hash) >= 1:
        return jsonify(message='This document is exist on '\
        'blockchain database'), 403
    else:
        return jsonify(message="Not exist"), 200
示例#3
0
def login():
    error = None
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        if not username:
            error = 'empty username'
        elif not password:
            error = 'empty password'
        else:
            cur = g.db.execute("SELECT username,password FROM accounts WHERE username=?", (username,))
            row = cur.fetchone()
            if not row:
                error = 'user not found'
            else:
                p_hash = row[1]
                print 'login,username='******'password='******'hash=', p_hash
                if utils.check_hash(username, app.config['SECRET_KEY'], password, p_hash):
                    session['logged_in'] = True
                    session['logged_user'] = request.form['username']
                    flash('You were logged in')
                    return redirect(url_for('show_entries'))
                else:
                    error = 'username and password not match'
    return render_template('login.html', error=error)
示例#4
0
	def vms_get_user(self, username, password):
		user = self.vms_db.batch_users.find_one({'username': username})		
#		plaintext_password = aes.decryptData(vms_cipher_key, user['password'])
#		if user != None and password == plaintext_password:
#			user['password'] = plaintext_password
#			return user
		if user is not None and utils.check_hash(password, user['hash_password']):
			return user
		return False
示例#5
0
def get_company_from_API_key(public_key, private_key=None):
    company = models.Company.objects(public_key=public_key)
    if len(company) != 1:
        return None

    if private_key is not None:
        if not utils.check_hash(private_key, company.private_key_hash):
            return None

    return company[0]
示例#6
0
def get_private_key(password, user):

    if not utils.check_hash(password, user.password_hash):
        return None

    company_key = utils.decrypt(ciphertext=user.company_key_encrypted,
                                password=password)

    company = user.company

    private_key = utils.decrypt(ciphertext=company.private_key_encrypted,
                                password=company_key)

    return private_key
示例#7
0
def login():
    form = request.form
    email = form.get("email")
    password = form.get("password")

    user = get_user(email=email).first()
    if user is None:
        raise WebException("Invalid credentials.")

    if utils.check_hash(user.password, password):
        session["uid"] = user.uid
        session["logged_in"] = True
        return { "success": 1, "message": "Success!" }

    raise WebException("Invalid credentials.")
示例#8
0
def task_telecharger():
    for source in SOURCES:
        yield {
            "name":
            str(source.path),
            "targets": [SOURCE_DIR / source.filename],
            "actions": [
                (create_folder, [(SOURCE_DIR / source.filename).parent]),
                [
                    "curl",
                    "--silent",
                    "--output",
                    SOURCE_DIR / source.filename,
                    source.url,
                ],
            ],
            "uptodate":
            [check_hash(SOURCE_DIR / source.filename, source.hash)],
        }
示例#9
0
def login(email, password):
    logout()
    user = models.User.objects(email=email)
    if len(user) != 1:
        raise messages.user_not_found()
    user = user[0]
    if not utils.check_hash(string=password, hashed_string=user.password_hash):
        raise messages.user_not_found()

    session_id = utils.generate_id()

    while redisConnection.get("session:" + session_id) is not None:
        session_id = utils.generate_id()

    flask.session['id'] = session_id
    session_content = {"user_id": str(user.id)}
    session_content = json.dumps(session_content)
    redisConnection.set("session:" + session_id, session_content)

    return user
示例#10
0
    def post(self):

        username = self.get_argument('username')
        password = self.get_argument('password')
        next_url = self.get_argument('next', '')

        user =  User.objects(username=username).first()
        if user:

            if utils.check_hash(password, user.password):
                self.set_secure_cookie("userEasyMarketing", self.get_argument("username"))
                self.redirect(next_url or self.reverse_url('admin'))
            else:
                error = 'Incorrecto usuario o password'
                self.render(
                    'login.html',
                    error=error, next_url=next_url)
        else:
            error = 'Incorrecto usuario o password'
            self.render(
                'login.html',
                error=error, next_url=next_url)