コード例 #1
0
ファイル: server.py プロジェクト: kwugirl/Open-Sesame
def validate_login():
    form_email = urllib.quote(request.form['email'])

    try:
        form_password = decode_vector.decode(request.form['password'])
    except (TypeError, struct.error):
        flash('Password must be a motion gesture, please try again.')
        return redirect(url_for('index'))

    gesture = dtw_algorithm.create_gesture(form_password)

    authentication = False

    user = model.session.query(model.User).filter_by(email=form_email).first()

    if user:
        for password in user.password:
            # form password must be within user's own threshold for variability for at least one of 3 initial training samples
            if gesture - password <= user.threshold:
                authentication = True
                break

    if authentication is True:
        session['email'] = request.form['email']
        session['user_id'] = user.id

    else:
        flash('Please enter a valid username and password.')
        user = request.form['email']

    return redirect(url_for('index', user=user))
コード例 #2
0
def validate_login():
    form_email = urllib.quote(request.form['email'])

    try:
        form_password = decode_vector.decode(request.form['password'])
    except (TypeError, struct.error):
        flash('Password must be a motion gesture, please try again.')
        return redirect(url_for('index'))

    gesture = dtw_algorithm.create_gesture(form_password)

    authentication = False

    user = model.session.query(model.User).filter_by(email=form_email).first()

    if user:
        for password in user.password:
            # form password must be within user's own threshold for variability for at least one of 3 initial training samples
            if gesture - password <= user.threshold:
                authentication = True
                break

    if authentication is True:
        session['email'] = request.form['email']
        session['user_id'] = user.id

    else:
        flash('Please enter a valid username and password.')
        user = request.form['email']

    return redirect(url_for('index', user=user))
コード例 #3
0
def save_user():
    form_email = urllib.quote(request.form['email'])

    # checking that username was entered
    if form_email:
        # checking that username doesn't already exist in DB
        user = model.session.query(
            model.User).filter_by(email=form_email).first()

        if user:
            flash(
                'Username already taken, please choose a different username.')
            return redirect(url_for('create_user'))

    else:
        flash('Please enter a username.')
        return redirect(url_for('create_user'))

    try:
        # get gestures back into lists of xyz vector lists
        form_password1 = decode_vector.decode(request.form['password1'])
        form_password2 = decode_vector.decode(request.form['password2'])
        form_password3 = decode_vector.decode(request.form['password3'])
    except (TypeError, struct.error):
        flash('Password samples must be motion gestures, please try again.')
        return redirect(url_for('create_user'))

    gesture1 = dtw_algorithm.create_gesture(form_password1)
    gesture2 = dtw_algorithm.create_gesture(form_password2)
    gesture3 = dtw_algorithm.create_gesture(form_password3)

    gestures = [gesture1, gesture2, gesture3]

    # TODO: better way to do this combinatorics?
    # run DTW on all pairs of samples (3 choose 2 combinatorics), store greatest difference as user's personal threshold
    threshold = max(gesture1 - gesture2, gesture1 - gesture3,
                    gesture2 - gesture3)

    new_user = model.User(email=form_email,
                          password=gestures,
                          threshold=threshold)
    model.session.add(new_user)
    model.session.commit()

    flash('New user ' + request.form['email'] + ' created!')
    return redirect(url_for('index'))
コード例 #4
0
ファイル: server.py プロジェクト: kwugirl/Open-Sesame
def save_user():
    form_email = urllib.quote(request.form['email'])

    # checking that username was entered
    if form_email:
        # checking that username doesn't already exist in DB
        user = model.session.query(model.User).filter_by(email=form_email).first()

        if user:
            flash('Username already taken, please choose a different username.')
            return redirect(url_for('create_user'))

    else:
        flash('Please enter a username.')
        return redirect(url_for('create_user'))

    try:
        # get gestures back into lists of xyz vector lists
        form_password1 = decode_vector.decode(request.form['password1'])
        form_password2 = decode_vector.decode(request.form['password2'])
        form_password3 = decode_vector.decode(request.form['password3'])
    except (TypeError, struct.error):
        flash('Password samples must be motion gestures, please try again.')
        return redirect(url_for('create_user'))

    gesture1 = dtw_algorithm.create_gesture(form_password1)
    gesture2 = dtw_algorithm.create_gesture(form_password2)
    gesture3 = dtw_algorithm.create_gesture(form_password3)

    gestures = [gesture1, gesture2, gesture3]

    # TODO: better way to do this combinatorics?
    # run DTW on all pairs of samples (3 choose 2 combinatorics), store greatest difference as user's personal threshold
    threshold = max(gesture1 - gesture2, gesture1 - gesture3, gesture2 - gesture3)

    new_user = model.User(email=form_email, password=gestures, threshold=threshold)
    model.session.add(new_user)
    model.session.commit()

    flash('New user ' + request.form['email'] + ' created!')
    return redirect(url_for('index'))
コード例 #5
0
ファイル: test.py プロジェクト: haimianying/Open-Sesame
def test_dtw():
    # Christian's example from 4/10 talk
    """
    desired end matrix looks like this: doing min of (cell above, to left, or diagonal to the upper left), going from top left to bottom right:
    0       (1)inf (2)inf   (1)inf
    (1)inf  0       1       1
    (1)inf  0       1       1
    (2)inf  1       0       1
    (1)inf  1       1       0*
    """
    a = [1, 2, 1]
    b = [1, 1, 2, 1]
    assert(dtw_algorithm.dtw(a, b) == 0), "Basic Euclidean-distance based test failed"

    s1 = sine_wave(360, 1)
    s2 = sine_wave(360, 2)
    assert(dtw_algorithm.dtw(s1, s2) < 2), "Sine wave test failed"

    gesture_a = dtw_algorithm.create_gesture([[-7, -5, 4], [-8, -5, 4], [-8, -5, 4], [-8, -5, 4], [-8, -5, 4], [-8, -4, 3], [-9, -4, 3], [-9, -4, 3], [-9, -4, 3], [-9, -4, 3], [-8, -4, 3], [-8, -4, 4], [-8, -4, 4], [-8, -4, 4], [-8, -4, 5], [-7, -4, 6], [-6, -4, 6], [-6, -4, 7], [-6, -4, 7], [-5, -4, 8], [-4, -4, 9], [-3, -4, 10], [-3, -5, 10], [-3, -5, 10], [-3, -4, 10], [-2, -4, 9], [-2, -4, 8], [-2, -4, 7], [-2, -3, 6], [-2, -3, 5], [-2, -4, 5], [-2, -4, 5], [-2, -4, 5], [-3, -4, 5], [-3, -4, 6], [-5, -3, 7], [-6, -3, 8], [-8, -2, 9], [-9, -1, 10], [-10, -1, 11], [-11, 0, 11], [-11, 0, 12], [-11, 0, 12], [-11, -1, 11], [-11, -1, 11], [-10, -1, 11], [-9, -1, 11], [-8, -1, 11], [-7, -1, 11], [-7, 0, 11], [-7, 1, 11], [-6, 1, 11], [-6, 1, 11], [-6, 1, 11], [-6, 1, 11], [-6, 1, 10], [-5, 1, 9], [-5, 2, 8], [-5, 2, 7], [-6, 2, 6], [-6, 2, 4]])
    gesture_b = dtw_algorithm.create_gesture([[-7, -5, 4], [-8, -5, 4], [-8, -5, 4], [-8, -5, 4], [-8, -5, 4], [-8, -4, 3], [-9, -4, 3], [-9, -4, 3], [-9, -4, 3], [-9, -4, 3], [-8, -4, 3], [-8, -4, 4], [-8, -4, 4], [-8, -4, 4], [-8, -4, 5], [-7, -4, 6], [-6, -4, 6], [-6, -4, 7], [-6, -4, 7], [-5, -4, 8], [-4, -4, 9], [-3, -4, 10], [-3, -5, 10], [-3, -5, 10], [-3, -4, 10], [-2, -4, 9], [-2, -4, 8], [-2, -4, 7], [-2, -3, 6], [-2, -3, 5], [-2, -4, 5], [-2, -4, 5], [-2, -4, 5], [-3, -4, 5], [-3, -4, 6], [-5, -3, 7], [-6, -3, 8], [-8, -2, 9], [-9, -1, 10], [-10, -1, 11], [-11, 0, 11], [-11, 0, 12], [-11, 0, 12], [-11, -1, 11], [-11, -1, 11], [-10, -1, 11], [-9, -1, 11], [-8, -1, 11], [-7, -1, 11], [-7, 0, 11], [-7, 1, 11], [-6, 1, 11], [-6, 1, 11], [-6, 1, 11], [-6, 1, 11], [-6, 1, 10], [-5, 1, 9], [-5, 2, 8], [-5, 2, 7], [-6, 2, 6], [-6, 2, 4]])
    assert(gesture_a - gesture_b == 0), "Gesture objects failed"