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")
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")
def get_hash(key): """ Get hash value for a key. """ hash = new_hash(HASHING) hash.update(key) return hash.hexdigest()
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")
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)
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 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
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))
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()
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")
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()
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)
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
def fingerprint(self): return new_hash('ripemd160', sha256(self.serialized_key()).digest()).digest()[:4]
def address_from_pubkey(bytes): return address_from_pk_hash(new_hash('ripemd160', sha256(bytes).digest()).digest())
def address_from_pubkey(bytes): return address_from_pk_hash( new_hash('ripemd160', sha256(bytes).digest()).digest())
def _md4_hash(m: bytes): return new_hash('md4', m).digest()