Ejemplo n.º 1
0
        public bool AddUser(string userName, string password)
        {
            if (CheckIfUserExsit(userName))
            {
                return(false);
            }
            else
            {
                string hashedPass = BcryptHash.HashPassword(password);
                Console.WriteLine(hashedPass + "Here");

                Aes aes = new Aes();

                Console.WriteLine($" key {aes.GetKey()}");
                string cryptPass = aes.EncryptToBase64String(hashedPass);
                Console.WriteLine($" key {aes.GetKey()}");
                Console.WriteLine(aes.DecryptFromBase64String(cryptPass));

                userList.Add(new UserInfo {
                    UserID = userName, Password = cryptPass
                });

                mockDB.SetData(userList);

                return(true);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Decode encrypted user data
        /// </summary>
        /// <param name="email"></param>
        /// <param name="placeProviderId"></param>
        /// <returns></returns>
        public virtual async Task <User> GetUser(string email, string placeProviderId)
        {
            logger.LogInformation($"User loaded from database: {email}");
            var encoded = await redisCacheClient.Db0.HashGetAsync <string>($"{configuration["db-prefix"]}{REDIS_KEY_USERS_OBJECTS}", email);

            if (string.IsNullOrEmpty(encoded))
            {
                return(null);
            }
            using var aes = new Aes(configuration["key"], configuration["iv"]);
            var  decoded = aes.DecryptFromBase64String(encoded);
            User ret     = Newtonsoft.Json.JsonConvert.DeserializeObject <User>(decoded);

            // enhance user object for place provider groups
            if (!string.IsNullOrEmpty(placeProviderId))
            {
                var groups = await placeProviderRepository.GetUserGroups(email, placeProviderId);

                if (ret.Roles == null)
                {
                    ret.Roles = new List <string>();
                }
                foreach (var group in groups)
                {
                    if (!ret.Roles.Contains(group))
                    {
                        ret.Roles.Add(group);
                    }
                }
            }
            return(ret);
        }
        public override async Task <PlaceProviderSensitiveData> GetPlaceProviderSensitiveData(string placeProviderId)
        {
            var encoded = dataEncoded[placeProviderId];

            if (string.IsNullOrEmpty(encoded))
            {
                return(null);
            }
            using var aes = new Aes(configuration["key"], configuration["iv"]);
            var decoded = aes.DecryptFromBase64String(encoded);

            return(Newtonsoft.Json.JsonConvert.DeserializeObject <PlaceProviderSensitiveData>(decoded));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Decode visitor data from database
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public override async Task <VerificationData> GetResult(string id)
        {
            logger.LogInformation($"VerificationData loaded from database: {id.GetHashCode()}");
            var encoded = verification[id];

            if (string.IsNullOrEmpty(encoded))
            {
                return(null);
            }
            using var aes = new Aes(configuration["key"], configuration["iv"]);
            var decoded = aes.DecryptFromBase64String(encoded);

            return(Newtonsoft.Json.JsonConvert.DeserializeObject <VerificationData>(decoded));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Load PP sensitive data
        /// </summary>
        /// <param name="placeProviderId"></param>
        /// <returns></returns>
        public virtual async Task <PlaceProviderSensitiveData> GetPlaceProviderSensitiveData(string placeProviderId)
        {
            logger.LogInformation($"PP sensitive data loaded from database: {placeProviderId}");
            var encoded = await redisCacheClient.Db0.HashGetAsync <string>($"{configuration["db-prefix"]}{REDIS_KEY_PLACES_ENC_OBJECTS}", placeProviderId);

            if (string.IsNullOrEmpty(encoded))
            {
                return(null);
            }
            using var aes = new Aes(configuration["key"], configuration["iv"]);
            var decoded = aes.DecryptFromBase64String(encoded);

            return(Newtonsoft.Json.JsonConvert.DeserializeObject <PlaceProviderSensitiveData>(decoded));
        }
Ejemplo n.º 6
0
        public override async Task <Registration> GetRegistration(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(null);
            }

            logger.LogInformation($"Registration loaded from database: {(configuration["key"] + id).GetSHA256Hash()}");
            var encoded = registrations[id];

            if (string.IsNullOrEmpty(encoded))
            {
                return(null);
            }

            using var aes = new Aes(configuration["key"], configuration["iv"]);
            var decoded = aes.DecryptFromBase64String(encoded);

            return(Newtonsoft.Json.JsonConvert.DeserializeObject <Registration>(decoded));
        }
Ejemplo n.º 7
0
        public bool LogIn(string user, string pass)
        {
            if (FindUser(user))
            {
                Console.WriteLine(hiddenPass);
                Aes aes = new Aes();

                string decryptPass = aes.DecryptFromBase64String(hiddenPass);

                if (BcryptHash.ValidatePassword(pass, decryptPass))
                {
                    return(true);
                }

                else
                {
                    return(false);
                }
            }

            return(false);
        }