示例#1
0
def login_lms():
    """Login screen for application"""
    DEFAULT_NEXT = url_for('lms_admin.index')
    next = request.args.get('next', DEFAULT_NEXT)
    print next
    lmss = [ lt for lt in LearningTool.all() if len(lt.shindig_credentials) == 0 ]

    if request.method == 'GET':
        return render_template('login_lms.html', next=next, lmss=lmss, action_url = url_for('login_lms'))
    if request.method == 'POST' and 'username' in request.form:
        username = request.form['username']
        hashed = unicode(new_hash(ALGORITHM, request.form['password'].encode('utf8')).hexdigest())
        lms_id = request.form['lms']
        user = LtUser.exists(username, hashed, lms_id)
        if user is not None:
            if login_user(user):
                session['loggeduser'] = username
                session['last_request'] = time()
                session['usertype'] = 'lms'
                if next == DEFAULT_NEXT:
                    if user.access_level == 'instructor':
                        next = url_for('lms_instructor.index')
                return redirect(next)
            else:
                flash(gettext(u'Could not log in.'))
                return render_template('login_lms.html', next=next, lmss=lmss, action_url = url_for('login_lms'))
        else:
            flash(gettext(u'Invalid username.'))
            return render_template('login_lms.html', next=next, lmss=lmss, action_url = url_for('login_lms'))
    return gettext("Error in create_session")
示例#2
0
def login_admin():
    """Login screen for application"""

    next = request.args.get('next',url_for('admin.index'))

    if request.method == 'GET':
        return render_template('login_admin.html', next=next)
    if request.method == 'POST' and 'username' in request.form:
        username = request.form['username']
        hashed = unicode(new_hash(ALGORITHM, request.form['password'].encode('utf8')).hexdigest())
        user = LabManagerUser.exists(username, hashed)
        if user is not None:
            if login_user(user):
                session['loggeduser'] = username
                session['last_request'] = time()
                session['usertype'] = 'labmanager'
                next = request.args.get('next', url_for('admin.index'))
                return redirect(next)
            else:
                flash(gettext(u'Could not log in.'))
                return render_template('login_admin.html', next=next)
        else:
            flash(gettext(u'Invalid username.'))
            return render_template('login_admin.html', next=next)
    return gettext("Error in create_session")
示例#3
0
def get_hash(key):
    """
    Get hash value for a key.
    """
    hash = new_hash(HASHING)
    hash.update(key)
    return hash.hexdigest()
示例#4
0
def login_admin():
    """Login screen for application"""

    next = request.args.get('next', url_for('admin.index'))

    if request.method == 'GET':
        return render_template('login_admin.html', next=next)
    if request.method == 'POST' and 'username' in request.form:
        username = request.form['username']
        hashed = unicode(
            new_hash(ALGORITHM,
                     request.form['password'].encode('utf8')).hexdigest())
        user = LabManagerUser.exists(username, hashed)
        if user is not None:
            if login_user(user):
                session['loggeduser'] = username
                session['last_request'] = time()
                session['usertype'] = 'labmanager'
                next = request.args.get('next', url_for('admin.index'))
                return redirect(next)
            else:
                flash(gettext(u'Could not log in.'))
                return render_template('login_admin.html', next=next)
        else:
            flash(gettext(u'Invalid username.'))
            return render_template('login_admin.html', next=next)
    return gettext("Error in create_session")
示例#5
0
 def create_model(self, form):
     if form.password.data == '':
         form.password.errors.append(
             lazy_gettext("This field is required."))
         return False
     form.password.data = unicode(
         new_hash(ALGORITHM, form.password.data.encode('utf8')).hexdigest())
     return super(LtUsersPanel, self).create_model(form)
示例#6
0
def create_salted_password(password):
    alphabet = string.ascii_letters + string.digits
    CHARS = 6
    random_str = ""
    for _ in range(CHARS):
        random_str += random.choice(alphabet)

    salted_password = unicode(new_hash("sha", random_str + password).hexdigest())
    return random_str + "::" + salted_password
def create_salted_password(password):
    alphabet = string.ascii_letters + string.digits
    CHARS = 6
    random_str = ""
    for _ in range(CHARS):
        random_str += random.choice(alphabet)

    salted_password = unicode(new_hash("sha", random_str + password).hexdigest())
    return random_str + "::" + salted_password
示例#8
0
 def update_model(self, form, model):
     old_password = model.password
     if form.password.data != '':
         form.password.data = unicode(new_hash(ALGORITHM, form.password.data.encode('utf8')).hexdigest())
     return_value = super(LmsUsersPanel, self).update_model(form, model)
     if form.password.data == '':
         model.password = old_password
         self.session.add(model)
         self.session.commit()
     return return_value
示例#9
0
def GeneratePassword_Deprecated(charset, passString, passLength):
    """
    This function creates a pseudo random number generator object, seeded with
    the cryptographic hash of the passString. The contents of the character set
    is then shuffled and a selection of passLength words is made from this list.
    This selection is returned as the generated password.
    """
    l = list(charset)
    s = new_hash(passString)
    r = random.Random(long(s.hexdigest(), 16))
    return "".join(r.sample(l, passLength))
示例#10
0
def create_hash(algorithm, seed=None, random_bytes=32, use_bin=False):
    if algorithm not in algorithms_available:
        return None
    h = new_hash(algorithm)
    if seed is None:
        h.update(urandom(random_bytes))
    else:
        h.update(seed.encode("utf-8"))
    if use_bin:
        return h.digest()
    return h.hexdigest()
示例#11
0
def login_lms():
    """Login screen for application"""
    DEFAULT_NEXT = url_for('lms_admin.index')
    next = request.args.get('next', DEFAULT_NEXT)
    print next
    lmss = [
        lt for lt in LearningTool.all() if len(lt.shindig_credentials) == 0
    ]

    if request.method == 'GET':
        return render_template('login_lms.html',
                               next=next,
                               lmss=lmss,
                               action_url=url_for('login_lms'))
    if request.method == 'POST' and 'username' in request.form:
        username = request.form['username']
        hashed = unicode(
            new_hash(ALGORITHM,
                     request.form['password'].encode('utf8')).hexdigest())
        lms_id = request.form['lms']
        user = LtUser.exists(username, hashed, lms_id)
        if user is not None:
            if login_user(user):
                session['loggeduser'] = username
                session['last_request'] = time()
                session['usertype'] = 'lms'
                if next == DEFAULT_NEXT:
                    if user.access_level == 'instructor':
                        next = url_for('lms_instructor.index')
                return redirect(next)
            else:
                flash(gettext(u'Could not log in.'))
                return render_template('login_lms.html',
                                       next=next,
                                       lmss=lmss,
                                       action_url=url_for('login_lms'))
        else:
            flash(gettext(u'Invalid username.'))
            return render_template('login_lms.html',
                                   next=next,
                                   lmss=lmss,
                                   action_url=url_for('login_lms'))
    return gettext("Error in create_session")
示例#12
0
def seeded_range(seed, start, stop=None, step=1, extra=None):
    """
    A filter to produce deterministic random numbers.

    Produce a random item from range(start, stop[, step]), use the value and
    optional ``extra`` value to set the seed for the random number generator.

    Basic usage::

        ansible_fqdn|seeded_range(60)

        "hello"|seeded_range(1, 10, extra="world")
    """
    hashed_seed = new_hash('sha1')
    hashed_seed.update(seed)

    if extra is not None:
        hashed_seed.update(extra)

    hashed_seed = hashed_seed.digest()

    # We rely on randrange's interpretation of parameters
    return Random(hashed_seed).randrange(start, stop, step)
示例#13
0
def seeded_range(seed, start, stop=None, step=1, extra=None):
    """
    A filter to produce deterministic random numbers.

    Produce a random item from range(start, stop[, step]), use the value and
    optional ``extra`` value to set the seed for the random number generator.

    Basic usage::

        ansible_fqdn|seeded_range(60)

        "hello"|seeded_range(1, 10, extra="world")
    """
    hashed_seed = new_hash('sha1')
    hashed_seed.update(seed)

    if extra is not None:
        hashed_seed.update(extra)

    hashed_seed = hashed_seed.digest()

    # We rely on randrange's interpretation of parameters
    return Random(hashed_seed).randrange(start, stop, step)
def _md4_hash(m):
    return new_hash('md4', m).digest()
示例#15
0
 def create_model(self, form):
     if form.password.data == '':
         form.password.errors.append(lazy_gettext("This field is required."))
         return False
     form.password.data = unicode(new_hash(ALGORITHM, form.password.data.encode('utf8')).hexdigest())
     return super(LmsUsersPanel, self).create_model(form)
示例#16
0
def check_salted_password(password, salted_password):
    random_str = salted_password[:6]
    rest = salted_password[8:]
    salted = unicode(new_hash("sha", random_str + password).hexdigest())
    return rest == salted
示例#17
0
 def fingerprint(self):
     return new_hash('ripemd160', sha256(self.serialized_key()).digest()).digest()[:4]
示例#18
0
def check_salted_password(password, salted_password):
    random_str = salted_password[:6]
    rest = salted_password[8:]
    salted = unicode(new_hash("sha", random_str + password).hexdigest())
    return rest == salted
示例#19
0
def address_from_pubkey(bytes):
    return address_from_pk_hash(new_hash('ripemd160', sha256(bytes).digest()).digest())
示例#20
0
def address_from_pubkey(bytes):
    return address_from_pk_hash(
        new_hash('ripemd160',
                 sha256(bytes).digest()).digest())
示例#21
0
def _md4_hash(m: bytes):
    return new_hash('md4', m).digest()
示例#22
0
 def fingerprint(self):
     return new_hash('ripemd160',
                     sha256(self.serialized_key()).digest()).digest()[:4]