コード例 #1
0
        public List <AccountVaultEntity> decipheredListOfVaultAccounts(PMS_DBEntities db)
        {
            byte[] decryptedDBData = new byte[] { };
            List <AccountsVault>      listOfDBAccountsVault = db.AccountsVaults.ToList();
            List <AccountVaultEntity> decryptedData         = new List <AccountVaultEntity>();
            List <int> IDs = new List <int>();

            foreach (AccountsVault index in listOfDBAccountsVault)
            {
                byte[] encryptedDBData = index.Application;
                Utility.encryptedAccountVaultArray = encryptedDBData;
                int recID = index.Id;

                if (listOfDBAccountsVault.Count > 1)
                {
                    Utility.accountVaultID = index.Id;
                    IDs.Add(Utility.accountVaultID);
                }
                else
                {
                    Utility.accountVaultID = index.Id;
                }


                decryptedDBData = cryptoObj.decrypt(encryptedDBData, Utility.storedApplicationPrivateKey);

                string   strResult = Utility.stringManipulation(decryptedDBData);
                string[] stringArr = strResult.Split(new string[] { "  " },
                                                     StringSplitOptions.None);
                string[] cleanStrArray = stringArr.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                if (cleanStrArray != null && cleanStrArray.Count() > 0)
                {
                    if (Utility.allFieldsEntered == true)
                    {
                        AccountVaultEntity accountVaultObj = new AccountVaultEntity();
                        accountVaultObj.Id = recID;
                        accountVaultObj.applicationName = cleanStrArray[0];
                        accountVaultObj.username        = cleanStrArray[1].TrimStart();
                        accountVaultObj.password        = cleanStrArray[2].TrimStart();
                        accountVaultObj.applicationUrl  = cleanStrArray[3];
                        accountVaultObj.notes           = cleanStrArray[4];

                        decryptedData.Add(accountVaultObj);
                    }
                }
                else
                {
                    Utility.getText = "Something went wrong \n with the decryption!";
                }
            }

            Utility.listOfIDs = IDs;

            return(decryptedData);
        }
コード例 #2
0
ファイル: User.cs プロジェクト: LindaMotaung/PMS
 public byte[] getConfirmationCode()
 {
     byte[] finalResult = new byte[] { };
     using (var db = new PMS_DBEntities())
     {
         //The last Reset Password Request is stored within the last record in the confirmationCode table
         var result = db.ConfirmationCodes.Last();
         finalResult = result.ConfirmationCode1;
     }
     return(finalResult);
 }
コード例 #3
0
        public void addAcccount(string[] array)
        {
            using (var db = new PMS_DBEntities())
            {
                byte[] byteArray = Utility.objectToByteArray(array);

                cryptoObj.createKeys(Utility.storedApplicationPrivateKey, Utility.storedApplicationPublicKey);
                byte[] encrytedData = cryptoObj.encrypt(byteArray, Utility.storedApplicationPublicKey);

                insertApplicationAccountIntoDB(encrytedData);
                Utility.decryptedAccountsVaultList = decipheredListOfVaultAccounts(db);
            }
        }
コード例 #4
0
ファイル: User.cs プロジェクト: LindaMotaung/PMS
        public void login(string[] array)
        {
            using (var db = new PMS_DBEntities())
            {
                string usernameInput = string.Empty;
                string passwordInput = string.Empty;
                int    counter       = 0;

                if (array != null && array.Count() > 0)
                {
                    usernameInput = array[0];
                    passwordInput = array[1];
                }

                List <UserAccountEntity> dbListOfUsers = decipheredListOfDBUsers(db);
                if (dbListOfUsers != null && dbListOfUsers.Count > 0)
                {
                    foreach (var index in dbListOfUsers)
                    {
                        counter++;
                        if (index.username == usernameInput.Trim() &&
                            index.password == passwordInput)
                        {
                            frmMainPMSVaultForm mainForm = new frmMainPMSVaultForm(new ApplicationAccounts());
                            mainForm.Show();
                        }
                        else if (index.username == usernameInput.Trim() &&
                                 index.password != passwordInput)
                        {
                            Utility.getText   = "Username and/or password does not match!";
                            Utility.errorFlag = false;
                        }
                        else
                        {
                            if (counter == dbListOfUsers.Count)
                            {
                                if (Utility.isUserExists == false)
                                {
                                    Utility.getText = "User does not exists!";
                                }
                            }
                        }
                    }
                }
                else
                {
                    Utility.getText   = "User does not exist.\n Consider registering new account!";
                    Utility.errorFlag = false;
                }
            }
        }
コード例 #5
0
ファイル: User.cs プロジェクト: LindaMotaung/PMS
        //For every forgot password reset, there will be an encrypted entry in the ConfirmationCodes in the db
        //Iterate through list of encrypted confirmation code binary strings, decrypt each then
        //Check deciphered plain text against user input
        private List <ConfirmationCodesEntity> decipheredListOfConfirmationCodes(PMS_DBEntities db)
        {
            List <ConfirmationCode>        listOfDBConfirmationCodes = db.ConfirmationCodes.ToList();
            List <ConfirmationCodesEntity> decryptedData             = new List <ConfirmationCodesEntity>();

            foreach (var index in listOfDBConfirmationCodes)
            {
                byte[] encryptedDBData = index.ConfirmationCode1;

                //Decrypt confirmation code stored in DB
                byte[] decryptedDBData = cryptoObj.decrypt(encryptedDBData, Utility.confirmationCodePrivateKey);
                string strResult       = Encoding.UTF8.GetString(decryptedDBData);

                ConfirmationCodesEntity confirmationCodesObj = new ConfirmationCodesEntity();
                confirmationCodesObj.ConfirmationCode = strResult;
                decryptedData.Add(confirmationCodesObj);
            }

            return(decryptedData);
        }
コード例 #6
0
ファイル: User.cs プロジェクト: LindaMotaung/PMS
        public void registerAccount(string[] array)
        {
            using (var db = new PMS_DBEntities())
            {
                byte[] byteArray = Utility.objectToByteArray(array);

                //Generate Keys
                cryptoObj.createKeys(Utility.privateKey, Utility.publicKey);
                byte[] encrytedData = cryptoObj.encrypt(byteArray, Utility.publicKey);
                bool   isExist      = false;

                //First check if username does not exist
                UserData dbRec = db.UserDatas.FirstOrDefault(x => x.UserRSAEncryptedData == encrytedData);
                List <UserAccountEntity> listOfDBUsers = decipheredListOfDBUsers(db);
                foreach (var index in listOfDBUsers)
                {
                    if (index.username == array[0].Trim())
                    {
                        isExist = true;
                    }
                }

                if (dbRec != null || isExist == true)
                {
                    Utility.isUserExists = true;
                }

                if (isExist == false)
                {
                    insertNewUser(encrytedData);
                }
                else
                {
                    Utility.getText = "User already exists!";
                }
            }
        }
コード例 #7
0
ファイル: User.cs プロジェクト: LindaMotaung/PMS
        private List <UserAccountEntity> decipheredListOfDBUsers(PMS_DBEntities db)
        {
            byte[]                   decryptedDBData = new byte[] { };
            List <UserData>          listOfDBUsers   = db.UserDatas.ToList();
            List <UserAccountEntity> decryptedData   = new List <UserAccountEntity>();

            foreach (UserData index in listOfDBUsers)
            {
                byte[] encryptedDBData = index.UserRSAEncryptedData;
                Utility.encryptedByteArray = encryptedDBData;
                Utility.userDataID         = index.Id;

                if (Utility.resetPasswordFlag == true)
                {
                    decryptedDBData = cryptoObj.decrypt(encryptedDBData, Utility.mainPMSUpdatePrivateKey);
                }
                else
                {
                    decryptedDBData = cryptoObj.decrypt(encryptedDBData, Utility.privateKey);
                }

                string   strResult = Utility.stringManipulation(decryptedDBData);
                string[] stringArr = strResult.Split(new string[] { "  " },
                                                     StringSplitOptions.None);
                string[] cleanStrArray = stringArr.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                UserAccountEntity userAccObj = new UserAccountEntity();
                userAccObj.password         = cleanStrArray[2].TrimStart();
                userAccObj.username         = cleanStrArray[0];
                userAccObj.email            = cleanStrArray[1];
                userAccObj.passwordReminder = cleanStrArray[3];

                decryptedData.Add(userAccObj);
            }

            return(decryptedData);
        }
コード例 #8
0
ファイル: User.cs プロジェクト: LindaMotaung/PMS
        public bool forgotPassword(string usernameParams, string confirmationCode)
        {
            bool returnVal = false;

            using (var db = new PMS_DBEntities())
            {
                List <UserAccountEntity> decryptedData = decipheredListOfDBUsers(db);
                Utility.decryptedList = decryptedData;
                var resultList = Utility.decryptedList;

                //Verify if the user exists in the db
                var foundItem = resultList.Find(x => x.username.Trim() == usernameParams.Trim());
                if (foundItem != null)
                {
                    string getDBSecurityQuestion = string.Empty;

                    foreach (var index in resultList)
                    {
                        getDBSecurityQuestion = index.passwordReminder;
                    }

                    if (Utility.getPasswordReminder == getDBSecurityQuestion)
                    {
                        //Get the confirmation code that was encrypted in the db
                        List <ConfirmationCodesEntity> returnDBConfirmationCode = decipheredListOfConfirmationCodes(db);

                        //Compare decrypted confirmation code against user input
                        if (returnDBConfirmationCode != null && returnDBConfirmationCode.Count > 0)
                        {
                            foreach (var index in returnDBConfirmationCode)
                            {
                                if (index.ConfirmationCode.Trim() == confirmationCode.Trim())
                                {
                                    returnVal = true;
                                }
                                else
                                {
                                    Utility.getText   = "Confirmation Codes do not match!";
                                    Utility.errorFlag = false;
                                }
                            }
                        }
                        else
                        {
                            Utility.getText   = "Something went wrong with the \n confirmation code decryption!";
                            Utility.errorFlag = false;
                        }
                    }
                    else
                    {
                        Utility.errorFlag = false;
                        Utility.getText   = "Security question answered incorrectly!";
                    }
                }
                else
                {
                    Utility.errorFlag = false;
                    Utility.getText   = "The user does not exist!";
                }
            }
            return(returnVal);
        }
コード例 #9
0
 public void refreshData()
 {
     using (var db = new PMS_DBEntities())
         Utility.decryptedAccountsVaultList = decipheredListOfVaultAccounts(db);
 }