예제 #1
0
def register(request):
	if request.method == 'POST':
		error = []
		email = request.POST['email']
		if email == '':
			error.append("email")
		password = request.POST['password']
		re_password = request.POST['re-password']
		if password == re_password and password != '':
			password = handler.hash(password)
		else:
			error.append("password")
		first_name = request.POST['firstname']
		if first_name == '':
			error.append('first_name')
		last_name = request.POST['lastname']
		if last_name == '':
			error.append('last_name')
		address = request.POST['address']
		if address == '':
			error.append('address')
		city = request.POST['city']
		if city == '':
			error.append('city')
		state = request.POST['state']
		if state == '':
			error.append('state')
		country = request.POST['country']
		if country == '':
			error.append('country')
		zip_code = request.POST['zip']
		if zip_code == '':
			error.append('zip_code')
		user = User(email=email, password=password,first_name=first_name, last_name=last_name,
								address=address, city=city, state=state, country=country, zip_code=zip_code)
		if error:
			context = {
				'error': error,
				'email': email or None,
				'first_name': first_name or None,
				'last_name': last_name or None,
				'address': address or None,
				'city': city or None,
				'state': state or None,
				'country': country or None,
				'zip_code': zip_code or None
			}	
			return render(request, 'user/register.html', context) 
		else:
			user.save()
			return redirect('/user/login')
	else :
			return render(request, 'user/register.html')
예제 #2
0
def test_verify_password_single_hash_list(app, sqlalchemy_datastore):
    init_app_with_options(
        app, sqlalchemy_datastore, **{
            'SECURITY_PASSWORD_HASH':
            'bcrypt',
            'SECURITY_PASSWORD_SALT':
            'salty',
            'SECURITY_PASSWORD_SINGLE_HASH':
            ['django_pbkdf2_sha256', 'plaintext'],
            'SECURITY_PASSWORD_SCHEMES':
            ['bcrypt', 'pbkdf2_sha256', 'django_pbkdf2_sha256', 'plaintext']
        })
    with app.app_context():
        # double hash
        assert verify_password('pass', encrypt_password('pass'))
        assert verify_password('pass', pbkdf2_sha256.hash(get_hmac('pass')))
        # single hash
        assert verify_password('pass', django_pbkdf2_sha256.hash('pass'))
        assert verify_password('pass', plaintext.hash('pass'))
예제 #3
0
    def post(self, request):
        serializer = ForgotPasswordSerializer(data=request.data)
        #Generating Random Password of specific Type or use according to your need
        str_1 = [
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
        ]
        str_2 = ['!', '@', '#', '$', '%', '&', '*', '/', '-', '+']
        str_3 = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

        str = random.choice(str_1)
        for s in range(4):
            str += random.choice(str_1).lower()
        str += random.choice(str_2)
        for x in range(2):
            str += random.choice(str_3)

        password = handler.hash(str)

        if serializer.is_valid():
            email = request.data['email']
            print(email)
            MyUser.objects.filter(email=email).update(password=password)

            subject = 'Forgot Password Request'
            message = 'Your request for Forgot Password has been received, your new password is ' + str
            email_from = settings.EMAIL_HOST_USER
            recipient_list = [email]

            send_mail(
                subject,
                message,
                email_from,
                recipient_list,
                fail_silently=False,
            )
            return Response({'msg': 'done'}, status=status.HTTP_200_OK)
        else:
            return Response({'msg': 'Not a valid request'},
                            status=status.HTTP_400_BAD_REQUEST)
예제 #4
0
def test_verify_password_single_hash_list(app, sqlalchemy_datastore):
    init_app_with_options(
        app,
        sqlalchemy_datastore,
        **{
            "SECURITY_PASSWORD_HASH": "bcrypt",
            "SECURITY_PASSWORD_SALT": "salty",
            "SECURITY_PASSWORD_SINGLE_HASH": ["django_pbkdf2_sha256", "plaintext"],
            "SECURITY_PASSWORD_SCHEMES": [
                "bcrypt",
                "pbkdf2_sha256",
                "django_pbkdf2_sha256",
                "plaintext",
            ],
        }
    )
    with app.app_context():
        # double hash
        assert verify_password("pass", hash_password("pass"))
        assert verify_password("pass", pbkdf2_sha256.hash(get_hmac("pass")))
        # single hash
        assert verify_password("pass", django_pbkdf2_sha256.hash("pass"))
        assert verify_password("pass", plaintext.hash("pass"))
예제 #5
0
 def pre_commit_setup(self):
     """
     This method generates the required fields either from available
     information else automatic fields are generated.
     """
     self.password = django_pbkdf2_sha256.hash(self.password)
예제 #6
0
    stock_config = _apps.django16_context.to_dict()
    stock_rounds = 20000

stock_config.update(
    deprecated="auto",
    django_pbkdf2_sha1__default_rounds=stock_rounds,
    django_pbkdf2_sha256__default_rounds=stock_rounds,
)

# override sample hashes used in test cases
from passlib.hash import django_pbkdf2_sha256

sample_hashes = dict(django_pbkdf2_sha256=(
    "not a password",
    django_pbkdf2_sha256.hash("not a password",
                              rounds=stock_config.get(
                                  "django_pbkdf2_sha256__default_rounds"))))


#=============================================================================
# test utils
#=============================================================================
class _ExtensionSupport(object):
    """support funcs for loading/unloading extension"""
    #===================================================================
    # support funcs
    #===================================================================
    @classmethod
    def _iter_patch_candidates(cls):
        """helper to scan for monkeypatches.
예제 #7
0
 def generate_hash(password):
     return sha256.hash(password)
예제 #8
0
def Crypter(args):
    if args.encrypt == 'pbkdf2_sha256':
        return pbkdf2_sha256.hash(args.text)
    elif args.encrypt == 'oracle11':
        return oracle11.hash(args.text)
    elif args.encrypt == 'argon2':
        return argon2.hash(args.text)
    elif args.encrypt == 'bcrypt':
        return bcrypt.hash(args.text)
    elif args.encrypt == 'bcrypt_sha256':
        return bcrypt_sha256.hash(args.text)
    elif args.encrypt == 'cisco_asa':
        return cisco_asa.hash(args.text)
    elif args.encrypt == 'cisco_pix':
        return cisco_pix.hash(args.text)
    elif args.encrypt == 'cisco_type7':
        return cisco_type7.hash(args.text)
    elif args.encrypt == 'bigcrypt':
        return bigcrypt.hash(args.text)
    elif args.encrypt == 'bsdi_crypt':
        return bsdi_crypt.hash(args.text)
    elif args.encrypt == 'des_crypt':
        return des_crypt.hash(args.text)
    elif args.encrypt == 'hex_md4':
        return hex_md4.hash(args.text)
    elif args.encrypt == 'hex_md5':
        return hex_md5.hash(args.text)
    elif args.encrypt == 'hex_sha1':
        return hex_sha1.hash(args.text)
    elif args.encrypt == 'hex_sha256':
        return hex_sha256.hash(args.text)
    elif args.encrypt == 'hex_sha512':
        return hex_sha512.hash(args.text)
    elif args.encrypt == 'django_bcrypt':
        return django_bcrypt.hash(args.text)
    elif args.encrypt == 'django_disabled':
        return django_disabled.hash(args.text)
    elif args.encrypt == 'django_bcrypt_sha256':
        return django_bcrypt_sha256.hash(args.text)
    elif args.encrypt == 'django_des_crypt':
        return django_des_crypt.hash(args.text)
    elif args.encrypt == 'django_pbkdf2_sha1':
        return django_pbkdf2_sha1.hash(args.text)
    elif args.encrypt == 'django_pbkdf2_sha256':
        return django_pbkdf2_sha256.hash(args.text)
    elif args.encrypt == 'django_salted_md5':
        return django_salted_md5.hash(args.text)
    elif args.encrypt == 'django_salted_sha1':
        return django_salted_sha1.hash(args.text)
    elif args.encrypt == 'fshp':
        return fshp.hash(args.text)
    elif args.encrypt == 'ldap_bcrypt':
        return ldap_bcrypt.hash(args.text)
    elif args.encrypt == 'ldap_md5':
        return ldap_md5.hash(args.text)
    elif args.encrypt == 'ldap_plaintext':
        return ldap_plaintext.hash(args.text)
    elif args.encrypt == 'ldap_sha1':
        return ldap_sha1.hash(args.text)
    elif args.encrypt == 'ldap_bsdi_crypt':
        return ldap_bsdi_crypt.hash(args.text)
    elif args.encrypt == 'ldap_hex_md5':
        return ldap_hex_md5.hash(args.text)
    elif args.encrypt == 'ldap_hex_sha1':
        return ldap_hex_sha1.hash(args.text)
    elif args.encrypt == 'ldap_md5_crypt':
        return ldap_md5_crypt.hash(args.text)
    elif args.encrypt == 'ldap_pbkdf2_sha1':
        return ldap_pbkdf2_sha1.hash(args.text)
    elif args.encrypt == 'ldap_pbkdf2_sha256':
        return ldap_pbkdf2_sha256.hash(args.text)
    elif args.encrypt == 'ldap_pbkdf2_sha512':
        return ldap_pbkdf2_sha512.hash(args.text)
    elif args.encrypt == 'ldap_salted_md5':
        return ldap_salted_md5.hash(args.text)
    elif args.encrypt == 'ldap_salted_sha1':
        return ldap_salted_sha1.hash(args.text)
    elif args.encrypt == 'ldap_sha1_crypt':
        return ldap_sha1_crypt.hash(args.text)
    elif args.encrypt == 'ldap_sha256_crypt':
        return ldap_sha256_crypt.hash(args.text)
    elif args.encrypt == 'ldap_sha512_crypt':
        return ldap_sha512_crypt.hash(args.text)
    elif args.encrypt == 'apr_md5_crypt':
        return apr_md5_crypt.hash(args.text)
    elif args.encrypt == 'md5_crypt':
        return md5_crypt.hash(args.text)
    elif args.encrypt == 'plaintext':
        return plaintext.hash(args.text)
    elif args.encrypt == 'unix_disabled':
        return unix_disabled.hash(args.text)
    elif args.encrypt == 'unix_fallback':
        return unix_fallback.hash(args.text)
    elif args.encrypt == 'mssql2000':
        return mssql2000.hash(args.text)
    elif args.encrypt == 'mssql2005':
        return mssql2005.hash(args.text)
    elif args.encrypt == 'mysql323':
        return mysql323.hash(args.text)
    elif args.encrypt == 'mysql41':
        return mysql41.hash(args.text)
    elif args.encrypt == 'atlassian_pbkdf2_sha1':
        return atlassian_pbkdf2_sha1.hash(args.text)
    elif args.encrypt == 'cta_pbkdf2_sha1':
        return cta_pbkdf2_sha1.hash(args.text)
    elif args.encrypt == 'dlitz_pbkdf2_sha1':
        return dlitz_pbkdf2_sha1.hash(args.text)
    elif args.encrypt == 'grub_pbkdf2_sha512':
        return grub_pbkdf2_sha512.hash(args.text)
    elif args.encrypt == 'pbkdf2_sha1':
        return pbkdf2_sha1.hash(args.text)
    elif args.encrypt == 'pbkdf2_sha512':
        return pbkdf2_sha512.hash(args.text)
    elif args.encrypt == 'phpass':
        return phpass.hash(args.text)
    elif args.encrypt == 'roundup_plaintext':
        return roundup_plaintext.hash(args.text)
    elif args.encrypt == 'sun_md5_crypt':
        return sun_md5_crypt.hash(args.text)
    elif args.encrypt == 'scram':
        return scram.hash(args.text)
    elif args.encrypt == 'scrypt':
        return scrypt.hash(args.text)
    elif args.encrypt == 'sha1_crypt':
        return sha1_crypt.hash(args.text)
    elif args.encrypt == 'sha256_crypt':
        return sha256_crypt.hash(args.text)
    elif args.encrypt == 'sha512_crypt':
        return sha512_crypt.hash(args.text)
    elif args.encrypt == 'bsd_nthash':
        return bsd_nthash.hash(args.text)
    elif args.encrypt == 'lmhash':
        return lmhash.hash(args.text)
    elif args.encrypt == 'nthash':
        return nthash.hash(args.text)
    def post(self, request):
        try:

            Full_Name = request.data.get('Full_Name')
            Email = request.data.get('Email')
            Username = request.data.get('Username')
            Location = request.data.get('Location')
            PhoneNumber = request.data.get('PhoneNumber')
            Gender = request.data.get('Gender')
            Bloodgroup = request.data.get('Bloodgroup')
            Password = request.data.get('Password')
            Password = handler.hash(Password)
            Sender_ID = request.data.get('Sender_ID')
            Device_type = request.data.get('Device_type')
            latitude = request.data.get('latitude')
            longitude = request.data.get('longitude')

            checkEmailExist = Signup.objects.filter(Email=Email)
            if checkEmailExist:
                message = {
                    "status": False,
                    'message': "Email Already Exist",
                }
                return Response(message)

            checkUserName = Signup.objects.filter(Username=Username)
            if checkUserName:
                message = {
                    'status': False,
                    'message': "UserName Already Exist",
                }
                return Response(message)

            checkPhoneNumber = Signup.objects.filter(PhoneNumber=PhoneNumber)
            if checkPhoneNumber:
                message = {
                    'status': False,
                    'message': "Mobile Number Already Exist",
                }
                return Response(message)

            data = Signup(Full_Name=Full_Name,
                          Username=Username,
                          Email=Email,
                          Password=Password,
                          Sender_ID=Sender_ID,
                          Device_type=Device_type,
                          latitude=latitude,
                          longitude=longitude,
                          Location=Location,
                          PhoneNumber=PhoneNumber,
                          Gender=Gender,
                          Bloodgroup=Bloodgroup)
            data.save()

            userid = data.id

            try:

                fcm = FCMDevice(registration_id=Sender_ID,
                                name=userid,
                                type=Device_type)
                fcm.save()

            except:
                None

            fetch_userobeject = Signup.objects.get(Username=Username)
            serdata = SerSignup(fetch_userobeject)

            message = {
                "status": True,
                "message": "Account Created Successfully",
                "data": serdata.data
            }

            return Response(message)

        except Exception as e:

            data = {'status': False, 'message': str(e)}
            return Response(data)
예제 #10
0
def generate_password_hash(password):
    return handler.hash(secret=password)
예제 #11
0
    stock_config = _apps.django16_context.to_dict()
    stock_rounds = 24000
else:  # 1.8
    stock_config = _apps.django16_context.to_dict()
    stock_rounds = 20000

stock_config.update(
    deprecated="auto",
    django_pbkdf2_sha1__default_rounds=stock_rounds,
    django_pbkdf2_sha256__default_rounds=stock_rounds,
)

# override sample hashes used in test cases
from passlib.hash import django_pbkdf2_sha256
sample_hashes = dict(
    django_pbkdf2_sha256=("not a password", django_pbkdf2_sha256.hash("not a password",
                          rounds=stock_config.get("django_pbkdf2_sha256__default_rounds")))
)

#=============================================================================
# test utils
#=============================================================================
class _ExtensionSupport(object):
    """support funcs for loading/unloading extension"""
    #===================================================================
    # support funcs
    #===================================================================
    @classmethod
    def _iter_patch_candidates(cls):
        """helper to scan for monkeypatches.

        returns tuple containing:
예제 #12
0
from passlib.hash import django_pbkdf2_sha256
hash = django_pbkdf2_sha256.hash("password")
print(hash)

correct_password = django_pbkdf2_sha256.verify('paswdasd', hash)
print(correct_password)