Beispiel #1
0
        public string BuildCheckSumAvailable2(Wallet_Account CurrenctWalletAcc)
        {
            try
            {
                if (Globals.StampServerKey != "Invalid Key")
                {
                    //var logWallet = new LogWallet();
                    //logWallet.Log(MethodBase.GetCurrentMethod(), CurrenctWalletAcc.ID + "|" + CurrenctWalletAcc.Wallet_ID + "|" + CurrenctWalletAcc.Currency_Code + "|" + CurrenctWalletAcc.User_ID + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.CreateUser) ? "" : CurrenctWalletAcc.CreateUser.Trim()) + "|" + CurrenctWalletAcc.CreateDate + "|" + CurrenctWalletAcc.UpdateDate + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.UpdateUser) ? "" : CurrenctWalletAcc.UpdateUser.Trim()) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(CurrenctWalletAcc.Available_Balance) + "|" + Globals.StampServerKey, null, "BuildCheckSumAvailable2");
                    if (string.IsNullOrEmpty(Globals.StampServerKey))
                    {
                        localhost.EWallet_StampService stampService = new localhost.EWallet_StampService();
                        var EncryptTokenEBW = SimpleAesUtil.Encrypt(EwalletConstant.TokenEBW);
                        Globals.StampServerKey = stampService.Generate_Stamp_Key(EncryptTokenEBW);
                    }

                    return(SecurityLogic.GetSha1Hash(CurrenctWalletAcc.ID + "|" + CurrenctWalletAcc.Wallet_ID + "|" + CurrenctWalletAcc.Currency_Code + "|" + CurrenctWalletAcc.User_ID + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.CreateUser) ? "" : CurrenctWalletAcc.CreateUser.Trim()) + "|" + CurrenctWalletAcc.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + CurrenctWalletAcc.UpdateDate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.UpdateUser) ? "" : CurrenctWalletAcc.UpdateUser.Trim()) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(CurrenctWalletAcc.Available_Balance) + "|" + Globals.StampServerKey));
                }
                else
                {
                    //var logWallet = new LogWallet();
                    //logWallet.Log(MethodBase.GetCurrentMethod(), CurrenctWalletAcc.ID + "|" + CurrenctWalletAcc.Wallet_ID + "|" + CurrenctWalletAcc.Currency_Code + "|" + CurrenctWalletAcc.User_ID + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.CreateUser) ? "" : CurrenctWalletAcc.CreateUser.Trim()) + "|" + CurrenctWalletAcc.CreateDate + "|" + CurrenctWalletAcc.UpdateDate + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.UpdateUser) ? "" : CurrenctWalletAcc.UpdateUser.Trim()) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(CurrenctWalletAcc.Available_Balance) + "|" + Globals.StampServerKey, null, "BuildCheckSumAvailable2");

                    return("");
                }
            }
            catch (Exception ex)
            {
                var logWallet = new LogWallet();
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), CurrenctWalletAcc.Wallet_ID, ex, ""));
                return("");
            }
        }
Beispiel #2
0
 public MessagesReaderFromServiceJob()
 {
     _chatBL     = new ChatLogic();
     _securityBL = new SecurityLogic();
     _userList   = new List <string>();
     _userList.AddRange(_chatBL.GetUsers().Where(p => p.Name != CurrentUserName).Select(p => p.Name));
 }
Beispiel #3
0
        public string BuildCheckSumAvailable1(Wallet_Account CurrenctWalletAcc)
        {
            string checkSumAvailable1 = SecurityLogic.GetSha1Hash(CurrenctWalletAcc.ID + "|" + CurrenctWalletAcc.Wallet_ID + "|" + CurrenctWalletAcc.Currency_Code + "|" + CurrenctWalletAcc.User_ID + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.CreateUser) ? "" : CurrenctWalletAcc.CreateUser.Trim()) + "|" + CurrenctWalletAcc.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + CurrenctWalletAcc.UpdateDate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.UpdateUser) ? "" : CurrenctWalletAcc.UpdateUser.Trim()) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(CurrenctWalletAcc.Available_Balance) + "|" + EwalletConstant.WebserverKey);

            //var logWallet = new LogWallet();
            //logWallet.Log(MethodBase.GetCurrentMethod(), CurrenctWalletAcc.ID + "|" + CurrenctWalletAcc.Wallet_ID + "|" + CurrenctWalletAcc.Currency_Code + "|" + CurrenctWalletAcc.User_ID + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.CreateUser) ? "" : CurrenctWalletAcc.CreateUser.Trim()) + "|" + CurrenctWalletAcc.CreateDate + "|" + CurrenctWalletAcc.UpdateDate + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.UpdateUser) ? "" : CurrenctWalletAcc.UpdateUser.Trim()) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(CurrenctWalletAcc.Available_Balance) + "|" + EwalletConstant.WebserverKey, null, "BuildCheckSumAvailable1");

            return(checkSumAvailable1);
        }
Beispiel #4
0
 public ChatViewModel()
 {
     SendCommand = new DelegateCommand(ExecuteSendCommand);
     _chatBL     = new ChatLogic();
     _securityBL = new SecurityLogic();
     _listUser   = new ObservableCollection <string>();
     _listUser.AddRange(_chatBL.GetUsers().Where(p => p.Name != CurrentUserName).Select(p => p.Name).ToList());
     JobScheduler.Start();
     _timer          = new Timer();
     _timer.Interval = 2000;
     _timer.Elapsed += (sender, args) => ChatText = _chatBL.GenerateChatText(_selectedUserName);
     _timer.Start();
 }
        protected void btnLogin_Click1(object sender, EventArgs e)
        {
            string username = txtUserName.Text.Trim();
            string password = txtPassword.Text.Trim();

            if (SecurityLogic.AuthUser(username, password))
            {
                FormsAuthentication.RedirectFromLoginPage(username, false); // false for the presisten cookie
            }
            else
            {
                lblMsg.Text      = "Login Failed";
                lblMsg.ForeColor = System.Drawing.Color.Red;
            }
        }
 public string InsertUserRecord(User record)
 {
     try
     {
         using (var eWalletTransactionUnitOfWork = new WalletTransactionUow(new WalletEntities()))
         {
             record.User_ID = SecurityLogic.GenerateKey(30);
             eWalletTransactionUnitOfWork.BeginTransaction().DoInsert(record).EndTransaction();
         }
         return(record.User_ID);
     }
     catch (Exception ex)
     {
         var logWallet = new LogWallet();
         Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), record.User_ID, ex, ""));
         return("");
     }
 }
        public bool UpdateCheckSumSnapshot(string pChecksum)
        {
            var lstSnapshots = new List <Wallet_Snapshot>();
            var userLogic    = new WalletUserLogic(true);

            try
            {
                var logWallet = new LogWallet();
                WalletTransactionUow WalletTransactionUnitOfWork = null;
                using (WalletTransactionUnitOfWork = new WalletTransactionUow(new WalletEntities()))
                {
                    lstSnapshots = WalletTransactionUnitOfWork.GetSnapshotByCheckSum(pChecksum);
                    logWallet.Log(MethodBase.GetCurrentMethod(), "Log here 1: " + pChecksum + "|" + lstSnapshots.Count, null, "");
                    var S1 = "";
                    foreach (Wallet_Snapshot walletSnapShot in lstSnapshots)
                    {
                        walletSnapShot.Checksum = BuildCheckSum(walletSnapShot);
                        S1 += (walletSnapShot.ID + walletSnapShot.Account_ID + ConvertUtility.RoundToTwoDecimalPlaces(walletSnapShot.Balance) + walletSnapShot.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") + walletSnapShot.Currency_Code + walletSnapShot.Checksum);
                    }
                    logWallet.Log(MethodBase.GetCurrentMethod(), "Log here 2", null, "");
                    var S1Hash = SecurityLogic.GetSha1Hash(S1);
                    logWallet.Log(MethodBase.GetCurrentMethod(), "Log here 3" + S1Hash, null, "");
                    foreach (Wallet_Snapshot Wallet_Snapshot in lstSnapshots)
                    {
                        Wallet_Snapshot.Snapshot = S1Hash;
                    }

                    WalletTransactionUnitOfWork.DoUpdateMany(lstSnapshots).EndTransaction();

                    logWallet.Log(MethodBase.GetCurrentMethod(), "Finish Update UpdateCheckSumSnapshot", null, "");
                }

                return(true);
            }
            catch (Exception ex)
            {
                var logWallet = new LogWallet();
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), "", ex, ""));
                return(false);
            }
        }
        //private object ValidatePassword(object param)
        //{
        //    GetPassword(param);
        //    return string.IsNullOrEmpty(Password) ? "Password can not be empty." : null;
        //}

        //private object ValidateLogin(object param)
        //{
        //    GetPassword(param);
        //    return string.IsNullOrEmpty(Login) ? "Username can not be empty." : null;
        //}

        private void ExecuteLoginCommand(object param)
        {
            try
            {
                GetPassword(param);
                SecurityLogic securityLogic = new SecurityLogic();
                Dictionary <string, string> tokenDictionary = securityLogic.GetTokenDictionary(Login, Password);
                string token = tokenDictionary.ContainsKey("access_token") ? tokenDictionary["access_token"] : null;
                if (token == null)
                {
                    throw new Exception("Could not log in.");
                }
                securityLogic.SaveToken(token);

                ((System.Windows.Window)Window.Parent).Close();
            }
            catch (Exception e)
            {
                ShowErrorMessage(e.Message);
            }
        }
        public bool VerifySnapshot(string snapshotChecksum, out List <Wallet_Snapshot> snapshot)
        {
            bool result = false;

            snapshot = null;
            try
            {
                //var maxDate = new WalletSnapshotQueryBuilder(new WalletEntities()).AsQueryable().Max(s => s.CreateDateSnapshot);
                snapshot = new WalletSnapshotQueryBuilder(new WalletEntities()).HasSnapshotChecksum(snapshotChecksum).ToList();
                string S1     = string.Join("", snapshot.OrderBy(s => s.Account_ID).Select(r => r.ID + r.Account_ID + ConvertUtility.RoundToTwoDecimalPlaces(r.Balance) + ConvertUtility.RoundToTwoDecimalPlaces(r.Reward_Amount) + r.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") + r.Currency_Code + r.Checksum));
                var    S1Hash = SecurityLogic.GetSha1Hash(S1);
                result = S1Hash == snapshotChecksum;
            }
            catch (Exception ex)
            {
                var logWallet = new LogWallet();
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), "", ex, ""));
                result = false;
            }
            return(result);
        }
Beispiel #10
0
        public void Test1()
        {
            var            crypto        = A.Fake <ICrypto>();
            var            securityLogic = new SecurityLogic(crypto);
            var            repository    = A.Fake <IRepository>();
            ISecureStorage storage       = new SecureStorage(crypto, securityLogic, repository);

            var loginCredentials     = ObjectMother.CreateCredentials();
            var foreignCredentials   = ObjectMother.CreateCredentials();
            var encryptedCredentials = ObjectMother.CreateEncryptedCredentials();

            var secureHash = ObjectMother.CreateSecureHash();

            A.CallTo(() => crypto.GetSecureHash(loginCredentials)).Returns(secureHash);
            var largeHash = ObjectMother.CreateLargeHash();

            A.CallTo(() => crypto.GetLargeHash(loginCredentials)).Returns(largeHash);

            storage.Save(loginCredentials, foreignCredentials);

            A.CallTo(() => repository.SaveEncryptedCredentials(loginCredentials.Username, encryptedCredentials)).MustHaveHappened();
        }
Beispiel #11
0
        public string BuildCheckSumTotal2(Wallet_Account CurrenctWalletAcc)
        {
            if (string.IsNullOrEmpty(Globals.StampServerKey))
            {
                try
                {
                    localhost.EWallet_StampService stampService = new localhost.EWallet_StampService();
                    var EncryptTokenEBW = SimpleAesUtil.Encrypt(EwalletConstant.TokenEBW);
                    Globals.StampServerKey = stampService.Generate_Stamp_Key(EncryptTokenEBW);
                }
                catch (Exception ex)
                {
                    Globals.StampServerKey = "5tg8ENcfBwP2z8pWsI5lL8Hab0Tr9VZ5";
                }
            }

            string checkSumTotal2 = SecurityLogic.GetSha1Hash(CurrenctWalletAcc.ID + "|" + CurrenctWalletAcc.Wallet_ID + "|" + CurrenctWalletAcc.Currency_Code + "|" + CurrenctWalletAcc.User_ID + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.CreateUser) ? "" : CurrenctWalletAcc.CreateUser.Trim()) + "|" + CurrenctWalletAcc.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + CurrenctWalletAcc.UpdateDate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.UpdateUser) ? "" : CurrenctWalletAcc.UpdateUser.Trim()) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(CurrenctWalletAcc.Total_Balance) + "|" + Globals.StampServerKey);

            //var logWallet = new LogWallet();
            //logWallet.Log(MethodBase.GetCurrentMethod(), CurrenctWalletAcc.ID + "|" + CurrenctWalletAcc.Wallet_ID + "|" + CurrenctWalletAcc.Currency_Code + "|" + CurrenctWalletAcc.User_ID + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.CreateUser) ? "" : CurrenctWalletAcc.CreateUser.Trim()) + "|" + CurrenctWalletAcc.CreateDate + "|" + CurrenctWalletAcc.UpdateDate + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.UpdateUser) ? "" : CurrenctWalletAcc.UpdateUser.Trim()) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(CurrenctWalletAcc.Total_Balance) + "|" + Globals.StampServerKey, null, "BuildCheckSumTotal2");

            return(checkSumTotal2);
        }
Beispiel #12
0
        public string GenerateNewWalletAccount(string pUserID, string pUserCreate)
        {
            var lstWalletAccount = new List <Wallet_Account>();
            var lstWalletRule    = new List <Wallet_Rule>();
            //var lstInterestSnapshot = new List<Transaction_Interest_Snapshot>();
            var lstRewards     = new List <Wallet_Account_Reward>();
            var New_WalletUser = new Wallet_User();

            New_WalletUser.User_ID   = pUserID;
            New_WalletUser.Wallet_ID = SecurityLogic.GenerateKey(30);
            var curDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour,
                                       DateTime.Now.Minute, DateTime.Now.Second);
            WalletTransactionUow WalletTransactionUnitOfWork = new WalletTransactionUow(new WalletEntities());

            try
            {
                WalletTransactionUnitOfWork.BeginTransaction();
                WalletTransactionUnitOfWork.DoInsert(New_WalletUser).SaveAndContinue();

                using (var CurrenciesQueryBuilder = new CurrenciesQueryBuilder(new WalletEntities()))
                {
                    foreach (var CurrencyCode in CurrenciesQueryBuilder.ToList())
                    {
                        #region New Wallet Acc
                        Random random        = new Random();
                        var    New_walletAcc = new Wallet_Account();
                        New_walletAcc.ID                 = SecurityLogic.GenerateKey(30);
                        New_walletAcc.Wallet_ID          = New_WalletUser.Wallet_ID;
                        New_walletAcc.User_ID            = pUserID;
                        New_walletAcc.Available_Balance  = ConvertUtility.RoundToTwoDecimalPlaces(0);
                        New_walletAcc.Total_Balance      = ConvertUtility.RoundToTwoDecimalPlaces(0);
                        New_walletAcc.Currency_Code      = CurrencyCode.Currency_Code;
                        New_walletAcc.CreateDate         = curDate;
                        New_walletAcc.CreateUser         = pUserCreate;
                        New_walletAcc.UpdateDate         = curDate;
                        New_walletAcc.UpdateUser         = pUserCreate;
                        New_walletAcc.ChecksumAvailable1 = BuildCheckSumAvailable1(New_walletAcc);

                        var strCheckSum2 = BuildCheckSumAvailable2(New_walletAcc);
                        if (strCheckSum2 != "")
                        {
                            New_walletAcc.ChecksumAvailable2 = strCheckSum2;
                        }
                        else
                        {
                            var logWallet = new LogWallet();
                            Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), New_WalletUser.Wallet_ID, null, "Can not build checksum2"));
                            return("Failed");
                        }

                        New_walletAcc.ChecksumTotal1 = BuildCheckSumTotal1(New_walletAcc);
                        New_walletAcc.ChecksumTotal2 = BuildCheckSumTotal2(New_walletAcc);
                        lstWalletAccount.Add(New_walletAcc);
                        #endregion

                        #region New Wallet Rule
                        var New_WalletRule = new Wallet_Rule();
                        New_WalletRule.ID         = SecurityLogic.GenerateKey(30);
                        New_WalletRule.Account_ID = New_walletAcc.ID;

                        switch (CurrencyCode.Currency_Code)
                        {
                        case "VND":
                            New_WalletRule.Maximum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupAmount_VND;
                            New_WalletRule.Maximum_Withdraw_Amount = EwalletConstant.EWallet_LimitWithdrawAmount_VND;
                            New_WalletRule.Minimum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupMinimumAmount_VND;
                            break;

                        case "USD":
                            New_WalletRule.Maximum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupAmount_USD;
                            New_WalletRule.Maximum_Withdraw_Amount = EwalletConstant.EWallet_LimitWithdrawAmount_USD;
                            New_WalletRule.Minimum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupMinimumAmount_USD;
                            break;

                        case "SGD":
                            New_WalletRule.Maximum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupAmount_SGN;
                            New_WalletRule.Maximum_Withdraw_Amount = EwalletConstant.EWallet_LimitWithdrawAmount_SGN;
                            New_WalletRule.Minimum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupMinimumAmount_SGN;
                            break;

                        case "MYR":
                            New_WalletRule.Maximum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupAmount_MYR;
                            New_WalletRule.Maximum_Withdraw_Amount = EwalletConstant.EWallet_LimitWithdrawAmount_MYR;
                            New_WalletRule.Minimum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupMinimumAmount_MYR;
                            break;

                        case "THB":
                            New_WalletRule.Maximum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupAmount_THB;
                            New_WalletRule.Maximum_Withdraw_Amount = EwalletConstant.EWallet_LimitWithdrawAmount_THB;
                            New_WalletRule.Minimum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupMinimumAmount_THB;
                            break;

                        case "CNY":
                            New_WalletRule.Maximum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupAmount_CNY;
                            New_WalletRule.Maximum_Withdraw_Amount = EwalletConstant.EWallet_LimitWithdrawAmount_CNY;
                            New_WalletRule.Minimum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupMinimumAmount_CNY;
                            break;

                        case "KHR":
                            New_WalletRule.Maximum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupAmount_KHR;
                            New_WalletRule.Maximum_Withdraw_Amount = EwalletConstant.EWallet_LimitWithdrawAmount_KHR;
                            New_WalletRule.Minimum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupMinimumAmount_KHR;
                            break;

                        case "MMK":
                            New_WalletRule.Maximum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupAmount_MMK;
                            New_WalletRule.Maximum_Withdraw_Amount = EwalletConstant.EWallet_LimitWithdrawAmount_MMK;
                            New_WalletRule.Minimum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupMinimumAmount_MMK;
                            break;

                        case "Rp":
                            New_WalletRule.Maximum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupAmount_Rp;
                            New_WalletRule.Maximum_Withdraw_Amount = EwalletConstant.EWallet_LimitWithdrawAmount_Rp;
                            New_WalletRule.Minimum_Topup_Amount    = EwalletConstant.EWallet_LimitTopupMinimumAmount_Rp;
                            break;
                        }
                        New_WalletRule.CreateDate    = curDate;
                        New_WalletRule.UpdateDate    = curDate;
                        New_WalletRule.Currency_Code = CurrencyCode.Currency_Code;
                        lstWalletRule.Add(New_WalletRule);

                        #endregion

                        //#region New Interest Snapshot
                        //var TransactionInterest = new WalletInterestLogic();
                        //var Tran_interest = new Transaction_Interest_Snapshot();
                        //Tran_interest.ID = Guid.NewGuid().ToString();
                        //Tran_interest.Account_ID = New_walletAcc.ID;
                        //Tran_interest.Tran_ID = Guid.NewGuid().ToString();
                        //Tran_interest.Interest_Amount = 0;
                        //Tran_interest.Total_Amount = 0;
                        //Tran_interest.Createdate = DateTime.Now;
                        //Tran_interest.Remark = "";
                        //var TransactionLogic = new WalletTransactionLogic(true);
                        //Tran_interest.CheckSumInterest = TransactionInterest.BuildCheckSum_SnapshotInterest(Tran_interest);
                        //lstInterestSnapshot.Add(Tran_interest);
                        //#endregion

                        #region New Reward Account

                        var Transaction_Reward = new Wallet_Account_Reward();
                        Transaction_Reward.ID            = New_walletAcc.ID;
                        Transaction_Reward.Wallet_ID     = New_walletAcc.Wallet_ID;
                        Transaction_Reward.Reward_Amount = 0;
                        Transaction_Reward.Createdate    = curDate;
                        Transaction_Reward.Updatedate    = curDate;
                        Transaction_Reward.Remark        = "";
                        var TransactionRewardLogic = new WalletRewardLogic();
                        Transaction_Reward.CheckSumReward = TransactionRewardLogic.BuildCheckSum_Reward(Transaction_Reward);
                        lstRewards.Add(Transaction_Reward);
                        #endregion
                    }
                }

                WalletTransactionUnitOfWork.DoInsertMany(lstWalletAccount);
                WalletTransactionUnitOfWork.DoInsertMany(lstWalletRule);
                //WalletTransactionUnitOfWork.DoInsertMany(lstInterestSnapshot);
                WalletTransactionUnitOfWork.DoInsertMany(lstRewards);
                WalletTransactionUnitOfWork.EndTransaction();

                return(New_WalletUser.Wallet_ID);
            }
            catch (Exception ex)
            {
                WalletTransactionUnitOfWork.RollBack();
                var logWallet = new LogWallet();
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), New_WalletUser.Wallet_ID, ex, ""));
                return("Failed");
            }
        }
Beispiel #13
0
        //Reset Password
        public static Boolean GeneratePasswordResetToken(AccountViewModel_GeneratePasswordResetToken view, string ConnectionString, SecurityLogic security)
        {
            try
            {
                DataAccess dataAccess = new DataAccess(ConnectionString, "spAccounts_GeneratePasswordResetToken");
                dataAccess.SetParamater_Input("@LoginID", view.LoginID, SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Input("@Key", security.GenerateSaltedHash(view.key, Encoding.ASCII.GetBytes(view.salt)), SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Input("@Salt", view.salt, SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Output("@outAccountID", SqlDbType.Int);
                dataAccess.SetParamater_Output("@outEmail", SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Output("@outGUID", SqlDbType.VarChar, 100);
                dataAccess.ExecuteNonQuery();

                view.AccountID = (int?)(dataAccess.GetParamater("@outAccountID"));
                view.Email     = (string)(dataAccess.GetParamater("@outEmail"));
                view.GUID      = (string)(dataAccess.GetParamater("@outGUID"));
                return(true);
            }
            catch (Exception ex)
            {
                view.Errors.Add(ex.Message);
                return(false);
            }
        }
Beispiel #14
0
        public static Boolean ResetPassword(AccountViewModel_ResetPassword resetPasswordView, AccountViewModel_VerifyPasswordResetToken verifyTokenView, string ConnectionString, SecurityLogic security)
        {
            try
            {
                DataAccess dataAccess = new DataAccess(ConnectionString, "spAccounts_ResetPassword");
                dataAccess.SetParamater_Input("@TokenID", verifyTokenView.TokenID, SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Input("@TokenKey", security.GenerateSaltedHash(verifyTokenView.TokenKey, Encoding.ASCII.GetBytes(verifyTokenView.TokenSalt)), SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Input("@Password", security.GenerateSaltedHash(resetPasswordView.password, Encoding.ASCII.GetBytes(resetPasswordView.passwordSalt)), SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Input("@Salt", resetPasswordView.passwordSalt, SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Output("@outAccountID", SqlDbType.Int);
                dataAccess.ExecuteNonQuery();

                resetPasswordView.AccountID = (int?)(dataAccess.GetParamater("@outAccountID"));
                return(true);
            }
            catch (Exception ex)
            {
                resetPasswordView.Errors.Add(ex.Message);
                return(false);
            }
        }
Beispiel #15
0
 public System.Collections.Generic.List <string> FetchDefinitions()
 {
     return(SecurityLogic.FetchDefinitions());
 }
Beispiel #16
0
        //Register
        public static Boolean Register(AccountViewModel_Registration view, string ConnectionString, SecurityLogic security)
        {
            try
            {
                DataAccess dataAccess = new DataAccess(ConnectionString, "spAccounts_Registration");
                dataAccess.SetParamater_Input("@Username", view.username, SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Input("@Email", view.email, SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Input("@FirstName", view.firstname, SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Input("@LastName", view.lastname, SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Input("@Hash", security.GenerateSaltedHash(view.password, Encoding.ASCII.GetBytes(view.salt)), SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Input("@Salt", view.salt, SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Output("@AccountID", SqlDbType.Int);
                dataAccess.SetParamater_Output("@EmailVerificationToken", SqlDbType.VarChar, 100);
                dataAccess.SetParamater_Output("@EmailVerificationKey", SqlDbType.VarChar, 100);
                dataAccess.ExecuteNonQuery();

                view.AccountID = (int?)(dataAccess.GetParamater("@AccountID"));
                view.EmailVerificationToken = (string)(dataAccess.GetParamater("@EmailVerificationToken"));
                view.EmailVerificationKey   = (string)(dataAccess.GetParamater("@EmailVerificationKey"));
                return(true);
            }
            catch (Exception ex)
            {
                view.Errors.Add(ex.Message);
                return(false);
            }
        }
Beispiel #17
0
 public ActiveDirectoryInfo GetActiveDirectoryInfo()
 {
     return(Invoke(() => SecurityLogic.GetActiveDirectoryInfo()));
 }
Beispiel #18
0
 public MockedSecurityLogic()
 {
     SecurityLogic = new SecurityLogic();
 }
Beispiel #19
0
        public void SetUp()
        {
            crypto = A.Fake <ICrypto>();

            sut = new SecurityLogic(crypto);
        }
Beispiel #20
0
 public static Boolean UpdatePassword(AccountViewModel_UpdatePassword view, string ConnectionString, SecurityLogic security)
 {
     try
     {
         DataAccess dataAccess = new DataAccess(ConnectionString, "spAccounts_UpdatePassword");
         dataAccess.SetParamater_Input("@AccountID", view.AccountID, SqlDbType.Int);
         dataAccess.SetParamater_Input("@CurPassword", security.GenerateSaltedHash(view.curpassword, Encoding.ASCII.GetBytes(view.cursalt)), SqlDbType.VarChar, 100);
         dataAccess.SetParamater_Input("@NewPassword", security.GenerateSaltedHash(view.newpassword, Encoding.ASCII.GetBytes(view.newsalt)), SqlDbType.VarChar, 100);
         dataAccess.SetParamater_Input("@NewSalt", view.newsalt, SqlDbType.VarChar, 100);
         dataAccess.ExecuteNonQuery();
         return(true);
     }
     catch (Exception ex)
     {
         view.Errors.Add(ex.Message);
         return(false);
     }
 }
Beispiel #21
0
        //Login
        public static Boolean Login(AccountViewModel_Login view, AccountViewModel AccountView, string ConnectionString, SecurityLogic security)
        {
            if (!GetSalt(view, ConnectionString))
            {
                AccountView.Errors.Add(view.Errors.First());
                return(false);
            }
            else
            {
                if (view.salt != null)
                {
                    try
                    {
                        DataAccess dataAccess = new DataAccess(ConnectionString, "spAccounts_Login");


                        dataAccess.SetParamater_Input("@LoginID", view.Login, SqlDbType.VarChar, 100);
                        dataAccess.SetParamater_Input("@Hash", security.GenerateSaltedHash(view.password, Encoding.ASCII.GetBytes(view.salt)), SqlDbType.VarChar, 100);

                        dataAccess.SetParamater_Output("@outAccountID", SqlDbType.Int);
                        dataAccess.SetParamater_Output("@outUsername", SqlDbType.VarChar, 100);
                        dataAccess.SetParamater_Output("@outEmail", SqlDbType.VarChar, 100);
                        dataAccess.SetParamater_Output("@outFirstName", SqlDbType.VarChar, 100);
                        dataAccess.SetParamater_Output("@outLastName", SqlDbType.VarChar, 100);
                        dataAccess.SetParamater_Output("@outCretedOn", SqlDbType.DateTime);
                        dataAccess.SetParamater_Output("@outLastEditedOn", SqlDbType.DateTime);

                        dataAccess.ExecuteNonQuery();

                        AccountView.AccountID    = (int?)(dataAccess.GetParamater("@outAccountID"));
                        AccountView.username     = (string)(dataAccess.GetParamater("@outUsername"));
                        AccountView.email        = (string)(dataAccess.GetParamater("@outEmail"));
                        AccountView.firstname    = (string)(dataAccess.GetParamater("@outFirstName"));
                        AccountView.lastname     = (string)(dataAccess.GetParamater("@outLastName"));
                        AccountView.CreatedOn    = (DateTime?)(dataAccess.GetParamater("@outCretedOn"));
                        AccountView.LastEditedOn = (DateTime?)(dataAccess.GetParamater("@outLastEditedOn"));

                        return(true);
                    }
                    catch (Exception ex)
                    {
                        AccountView.Errors.Add(ex.Message);
                        return(false);
                    }
                }
                else
                {
                    AccountView.Errors.Add(view.Errors.First());
                    return(false);
                }
            }
        }
        public bool InsertSnapshot(string now)
        {
            var lstRewardAcc      = new List <Wallet_Account_Reward>();
            var lstWalletSnapshot = new List <Wallet_Snapshot>();
            var userLogic         = new WalletUserLogic(true);

            try
            {
                var DateSnapshot = new WalletSnapshotQueryBuilder(new WalletEntities()).GetLatestDateSnapshot().FirstOrDefault().CreateDateSnapshot;
                if (DateSnapshot.Year == int.Parse(now.Split('-')[0]) && DateSnapshot.Month == int.Parse(now.Split('-')[1]) && DateSnapshot.Day == int.Parse(now.Split('-')[2]))
                {
                    return(true);
                }
                WalletTransactionUow WalletTransactionUnitOfWork = null;
                using (WalletTransactionUnitOfWork = new WalletTransactionUow(new WalletEntities()))
                {
                    WalletTransactionUnitOfWork.BeginTransaction();
                    var lstWalletAccount = WalletTransactionUnitOfWork.GetAllWalletAccount().OrderBy(wa => wa.ID);
                    lstRewardAcc = WalletTransactionUnitOfWork.GetAllRewardAccount();
                    string S1 = "";
                    foreach (Wallet_Account walletAcc in lstWalletAccount)
                    {
                        var walletSnapShot = new Wallet_Snapshot();
                        walletSnapShot.ID         = Guid.NewGuid().ToString();
                        walletSnapShot.Account_ID = walletAcc.ID;
                        walletSnapShot.Balance    = walletAcc.Available_Balance;
                        if (lstRewardAcc != null)
                        {
                            var rewardACC = lstRewardAcc.Find(p => p.ID == walletAcc.ID);
                            if (rewardACC != null)
                            {
                                walletSnapShot.Reward_Amount = rewardACC.Reward_Amount;
                            }
                            else
                            {
                                walletSnapShot.Reward_Amount = 0;
                            }
                        }
                        else
                        {
                            walletSnapShot.Reward_Amount = 0;
                        }
                        walletSnapShot.CreateDate         = walletAcc.CreateDate;
                        walletSnapShot.UpdateDate         = walletAcc.UpdateDate;
                        walletSnapShot.CreateDateSnapshot = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour,
                                                                         DateTime.Now.Minute, DateTime.Now.Second);
                        walletSnapShot.Currency_Code = walletAcc.Currency_Code;
                        walletSnapShot.Checksum      = BuildCheckSum(walletSnapShot);
                        lstWalletSnapshot.Add(walletSnapShot);
                        S1 += walletSnapShot.ID + walletSnapShot.Account_ID + ConvertUtility.RoundToTwoDecimalPlaces(walletSnapShot.Balance) + ConvertUtility.RoundToTwoDecimalPlaces(walletSnapShot.Reward_Amount) + walletSnapShot.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") + walletSnapShot.Currency_Code + walletSnapShot.Checksum;
                    }
                    var S1Hash = SecurityLogic.GetSha1Hash(S1);
                    foreach (Wallet_Snapshot Wallet_Snapshot in lstWalletSnapshot)
                    {
                        Wallet_Snapshot.Snapshot = S1Hash;
                    }

                    WalletTransactionUnitOfWork.DoInsertMany(lstWalletSnapshot).EndTransaction();
                }
                return(true);
            }
            catch (Exception ex)
            {
                var logWallet = new LogWallet();
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), "", ex, ""));
                return(false);
            }
        }
        public string BuildCheckSum(Wallet_Snapshot pSnapshot)
        {
            string CheckSum = SecurityLogic.GetSha1Hash(pSnapshot.ID + "|" + pSnapshot.Account_ID + "|" + ConvertUtility.RoundToTwoDecimalPlaces(pSnapshot.Balance) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(pSnapshot.Reward_Amount ?? 0) + "|" + pSnapshot.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + pSnapshot.Currency_Code + "|" + Globals.StampServerKey);

            return(CheckSum);
        }
Beispiel #24
0
 public IEnumerable <AdGroupWithRoles> GetAllAdGroupWithRoles()
 {
     return(Invoke(() => SecurityLogic.GetAll()));
 }
Beispiel #25
0
 public AdGroupWithRoles SaveAdGroupWithRoles(AdGroupWithRoles adGroupWithRoles)
 {
     Invoke(() => SecurityLogic.Save(adGroupWithRoles));
     return(adGroupWithRoles);
 }
        public string BuildCheckSum_Reward(Wallet_Account_Reward InterestTran)
        {
            string checkSum = SecurityLogic.GetSha1Hash(InterestTran.ID + "|" + InterestTran.Wallet_ID + "|" + InterestTran.Createdate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + InterestTran.Updatedate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + InterestTran.Reward_Amount + "|" + EwalletConstant.WebserverKey);

            return(checkSum);
        }
Beispiel #27
0
 public ActiveDirectoryInfo SaveActiveDirectoryInfo(ActiveDirectoryInfo adInfo)
 {
     Invoke(() => SecurityLogic.SaveActiveDirectoryInfo(adInfo));
     return(adInfo);
 }
        public string BuildCheckSum_SnapshotInterest(Transaction_Interest_Snapshot InterestTran)
        {
            string checkSum = SecurityLogic.GetSha1Hash(InterestTran.ID + "|" + InterestTran.Account_ID + "|" + InterestTran.Createdate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + InterestTran.Total_Amount + "|" + InterestTran.Interest_Amount + "|" + EwalletConstant.WebserverKey);

            return(checkSum);
        }
Beispiel #29
0
        public bool InsertVerificationStatus(UserBankAccountRequest request)
        {
            try
            {
                var BankAcc = SimpleAesUtil.DecryptAES(request.AccountNumber, EwalletConstant.keyAES);
                BankAcc = BankAcc.Replace(EwalletConstant.strWord, "").Replace(" ", "").Replace("-", "");
                double Num;
                bool   isNum = double.TryParse(BankAcc, out Num);

                if (!isNum || BankAcc.Length < 8 || BankAcc.Length > 20)
                {
                    var logWallet = new LogWallet();
                    logWallet.Log(MethodBase.GetCurrentMethod(), "BankAcc: " + BankAcc, null, "Issue for BankACC");
                    return(false);
                }

                byte[] bytes = Convert.FromBase64String(request.urlBankAcc);
                request.FileNameBankAcc = "BankAcc_" + DateTime.Now.Ticks + request.FileNameBankAcc.Substring(request.FileNameBankAcc.LastIndexOf('.'), 4);
                var pathFileNameBankAcc = Path.Combine(EwalletConstant.EWalletPathPictureUpload, request.FileNameBankAcc);
                using (Image image = Image.FromStream(new MemoryStream(bytes)))
                {
                    image.Save(pathFileNameBankAcc);
                }

                bytes = Convert.FromBase64String(request.urlPassIC);
                request.FileNamePasIC = "BankPasIC_" + DateTime.Now.Ticks + request.FileNamePasIC.Substring(request.FileNamePasIC.LastIndexOf('.'), 4);
                var pathFileNamePasIC = Path.Combine(EwalletConstant.EWalletPathPictureUpload, request.FileNamePasIC);
                using (Image image = Image.FromStream(new MemoryStream(bytes)))
                {
                    image.Save(pathFileNamePasIC);
                }

                var userBankAccount = new User_Bank_Account
                {
                    ID            = SecurityLogic.GenerateKey(30),
                    BankCurrency  = request.BankCurrency,
                    CountryBank   = request.CountryBank,
                    BankName      = request.BankName,
                    AccountName   = request.AccountName,
                    AccountNumber = request.AccountNumber,
                    Verify        = "Pending",
                    urlBankAcc    = pathFileNameBankAcc,
                    urlPassIC     = pathFileNamePasIC,
                    User_ID       = request.User_ID,
                    BankCity      = request.BankCity,
                    BranchCode    = request.BranchCode,
                    BranchName    = request.BranchName,
                    Comments      = request.Comments,
                    Create_date   = DateTime.Now,
                    Update_date   = DateTime.Now,
                };


                WalletTransactionUow WalletTransactionUnitOfWork = new WalletTransactionUow(new WalletEntities());

                WalletTransactionUnitOfWork.BeginTransaction();
                WalletTransactionUnitOfWork.DoInsert(userBankAccount).SaveAndContinue();
                WalletTransactionUnitOfWork.EndTransaction();
                return(true);
            }
            catch (Exception ex)
            {
                var logWallet = new LogWallet();
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), request, ex, ""));
                return(false);
            }
        }
Beispiel #30
0
 public System.Collections.Generic.List <System.Tuple <string, FACTS.Framework.Security.SecurityAccess> > FetchPermissions()
 {
     return(SecurityLogic.FetchPermissions());
 }