#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, print_function, unicode_literals

import getpass
from passlib.hash import sha512_crypt


def prompt():
    password1, password2 = None, None

    prompt1 = 'Enter your desired password: '
    prompt2 = 'Once more: '
    invalid = "Error: your passwords didn't match.  Please try again.\n"

    password1 = getpass.getpass(prompt=prompt1)
    password2 = getpass.getpass(prompt=prompt2)

    while password1 != password2:
        print(invalid)
        password1 = getpass.getpass(prompt=prompt1)
        password2 = getpass.getpass(prompt=prompt2)

    return password1


def hash_password(password, rounds=5000):
    return sha512_crypt.encrypt(password, rounds=rounds)


def main():
    password = prompt()
    print()
    print('-------------------------------------')
    print('-- Your password hash is:')
    print(hash_password(password))
    print('-------------------------------------')


if __name__ == '__main__':
    main()
