def signup():
    if request.method == "POST":
        username = request.form.get("user")
        email = request.form.get("email")
        password = request.form.get("password")
        confirm = request.form.get("confirm")
        secure_pass = sha512_crypt.encrypt(str(password))
        if password == confirm:
            username_db = db.execute(
                'SELECT * FROM Users WHERE username = :username', {
                    "username": username
                }).fetchone()
            if username_db:
                flash("UserName already exist!", "danger")
            else:
                db.execute(
                    "insert into users(username, email, password) VALUES (:username,:email,:password)",
                    {
                        "username": username,
                        "email": email,
                        "password": secure_pass
                    })
                db.commit()
                flash("You have Registered Successfully", "success")
                return redirect(url_for('login'))
        else:
            flash("Password Did Not Match", "danger")
            return render_template("signup.html")

    return render_template("signup.html")
Beispiel #2
0
def register():
    if '_id' in session:
        return redirect_to_home()

    if request.method == 'POST':
        results = {
            'name': request.form['name'],
            'email': request.form['email'],
            'password': request.form['password']
        }

        # Time to validate the shit out of this thing
        error_list = []
        errors = False
        for key, value in results.items():
            if not value:
                error_list.append('Please specify a {0}!'.format(key.replace('_', ' ')))
                errors = True

            if key == 'email':
                if not re.match(r'[^@]+@[^@]+\.[^@]+', value):
                    error_list.append('Please specify a valid email address!')
                    errors = True

            if isinstance(value, str):
                if len(value) > 50:
                    error_list.append('The length of {0} cannot exceed 50.'.format(key.replace('_', ' ')))
                    errors = True

        captcha_payload = {'privatekey': CONFIG['recaptcha_private_key'],
                           'remoteip': request.remote_addr,
                           'challenge': request.form['recaptcha_challenge_field'],
                           'response': request.form['recaptcha_response_field']}
        captcha_response = requests.post('http://www.google.com/recaptcha/api/verify', captcha_payload)

        if 'true' not in captcha_response.text:
            error_list.append('The captcha answer you provided isn\'t correct.')
            errors = True

        if errors:
            return render_template('register.html', errors=error_list)

        password_hashed = sha512_crypt.encrypt(results['password'])

        verification_key = ''.join(random.choice(string.ascii_lowercase + string.digits) for i in range(32))

        conn = BRConnection()
        users = conn.users

        for _ in users.find({'email': results['email']}):
            return render_template('register.html', errors=['There is already a user with the email {0}. Maybe you already signed up?'.format(results['email'])])

        new_user = User(email=results['email'], name=results['name'], password=password_hashed, verification_key=verification_key)
        users.insert(new_user.data)

        resend_verification(results['email'])

        return render_template('register_success.html', name=results['name'])

    return render_template('register.html')
Beispiel #3
0
def _genHash(secret):
    '''
    Generate a new hash for new root value.
    '''

    hash_secret = sha512_crypt.encrypt(secret, salt_size=16, rounds=5000)

    return hash_secret
Beispiel #4
0
def change_password(user_id, new_pass):
    conn = BRConnection()
    users = conn.users

    user = get_user(user_id)
    if user is None:
        return False

    password_hashed = sha512_crypt.encrypt(new_pass)
    users.update({'_id': ObjectId(user_id)}, {'$set': {'password': password_hashed}})

    return True
def testPass(cryptPass):
    salt = cryptPass[0:2]
    dictFile = open('dictionary.txt', 'r')
    for word in dictFile.readline():
        word = word.split('\n')
        cryptWord = sha512_crypt.encrypt(word, salt=salt, rounds=5000)
        # cryptWord= crypt.crypt(word,salt)     ### only for unix (windows not,https://www.cnpython.com/qa/61413)
        try:
            if (cryptWord == cryptPass):
                print("[+] Found Password:"******"\n")
                return
        except:
            print("[-] Password Not Found.\n")
            return
Beispiel #6
0
def create_user(username: str, name: str, email: str,
                password: str) -> Optional[User]:
    if get_user_by_username_or_email(username, email):
        return None

    user = User()
    user.username = username
    user.email = email
    user.name = name
    user.password = crypto.encrypt(password, rounds=CRYPTO_ROUNDS)

    session = db.create_session()
    session.add(user)
    session.commit()

    return user
def on_rstudio_user(args):
    """
    Create a RStudio user or change the password of an existing user
    `rstudio_user username [-p password]`
    """
    args = parser.parse_args(shlex.split(args))
    if not args.password:
        random.seed = (os.urandom(1024))
        password = ''.join(random.choice(PASS_CHARS) for _ in range(PASS_LEN))
    else:
        password = args.password
    encrypted = sha512_crypt.encrypt(password)
    run_ansible_cmd(' '.join([
        'bin/activate live && bin/ap site_env.yml', '-e "tac_env=live"',
        '-e "rs_users=%s"' % str(
            [{'name': args.name, 'password': encrypted}]).replace(' ', ''),
        '--tags rs_users']),
        g.channel,
        on_success='created RStudio account for user %s; password: %s' % (
            args.name, password),
        verbose=args.verbose
    )
    return 'creating RStudio user %s' % args.name
Beispiel #8
0
def register():
    global name, email, username, password
    form = RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        name = form.name.data
        email = form.email.data
        username = form.username.data
        password = sha512_crypt.encrypt(str(form.password.data))


# Making Cursor Object For Query Execution
    cur = cnx.cursor()
    cur.execute(
        "INSERT INTO  users (name, email, username, password) VALUES (%s ,%s, %s ,%s)",
        (name, email, username, password))
    cnx.commit()
    cur.commit()
    cnx.close()

    flash('You are Registerd', 'Sucess')

    redirect(url_for('index'))
    return render_template('register.html')
    return render_template('register.html', form=form)
 def hash_text(plain_text_pw):
     hashed_text = sha512_crypt.encrypt(plain_text_pw, rounds=150000)
     return hashed_text
Beispiel #10
0
def hash_text(text: str) -> str:
    # rounds set randomish but high
    hashed_text = crypto.encrypt(text, rounds=171204)
    return hashed_text
Beispiel #11
0
 def hash_text(plain_password):
     hashed_text = sha512_crypt.encrypt(plain_password, rounds=150000)
     return hashed_text
 def hash_text(plain_text_password):
     hashed_text = sha512_crypt.encrypt(plain_text_password, rounds=150000)
     return hashed_text
Beispiel #13
0
 def set_password(self, password: str) -> None:
     self.password = sha512_crypt.encrypt(password)
def hash_text(text: str) -> str:
    return crypto.encrypt(text, rounds=171204)
Beispiel #15
0
def hash_text(text: str) -> str:
    hashed_text = sha512_crypt.encrypt(text, rounds=150_000)
    return hashed_text
def hash_text(text: str) -> str:
    hashed_text = crypto.encrypt(text, rounds=171204)
    return hashed_text
Beispiel #17
0
def hash_text(text: str) -> str:
    return sha512_crypt.encrypt(text, rounds=150000)