public UserTokenDTO LoginUser(string username, string password)
        {
            UserTokenDTO response = null;

            using (var entities = new UCAInvestDBEntities())
            {
                var dbResponse =
                    entities.users.SingleOrDefault(t => t.username == username);
                if (dbResponse != null)
                {
                    string salt = dbResponse.salt;
                    if (dbResponse.password == CryptoServices.SHA256Encrypt(password, salt))
                    {
                        response = GiveMeUniqueAvailableToken(dbResponse.user_id);
                    }
                }
            }

            return(response);
        }
        public UserTokenDTO RegisterUser(RegisterUserDTO userToRegister)
        {
            User addedUser = null;

            using (var entities = new UCAInvestDBEntities())
            {
                var dbResponse =
                    entities.users.SingleOrDefault(t => t.mail == userToRegister.mail || t.username == userToRegister.username);

                if (dbResponse == null)
                {
                    long   creationTimeStamp = Convert.ToInt64(TimeFunctions.DateTimeToUnixTimestamp(DateTime.Now));
                    string salt      = CryptoServices.GenerateGuid().Substring(0, 8);
                    string password  = CryptoServices.SHA256Encrypt(userToRegister.password, salt);
                    var    userToAdd = new User()
                    {
                        first_name         = userToRegister.first_name,
                        mail               = userToRegister.mail,
                        last_name          = userToRegister.last_name,
                        mobile_phone       = userToRegister.mobile_phone,
                        creation_timestamp = creationTimeStamp,
                        password           = password,
                        salt               = salt,
                        username           = userToRegister.username,
                        status             = "freeuser"
                    };
                    addedUser = entities.users.Add(userToAdd);
                    entities.SaveChanges();
                }
            }

            if (addedUser != null)
            {
                return(GiveMeUniqueAvailableToken(addedUser.user_id));
            }

            return(null);
        }