Пример #1
0
        public void TestAesEncryptDecrypt_256_Cbc()
        {
            foreach (string item in data)
            {
                var encrypted = aes256Cbc.Encrypt(item);
                var decrypted = aes256Cbc.Decrypt(encrypted);

                Assert.AreEqual(decrypted, item);
            }
        }
Пример #2
0
        public void TestAesEncryptDecrypt_192_Cfb()
        {
            foreach (string item in data)
            {
                var encrypted = aes192Cfb.Encrypt(item);
                var decrypted = aes192Cfb.Decrypt(encrypted);

                Assert.AreEqual(decrypted, item);
            }
        }
Пример #3
0
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                string dir = "FolderLockData";

                if (File.Exists("data\\" + dir + "\\data.ls"))
                {
                    var    streamr      = new StreamReader("data\\" + dir + "\\data.ls");
                    string encsavedpath = streamr.ReadLine();
                    string decsavedpath = AesCrypt.Decrypt(encsavedpath);
                    checkBox1.Text = decsavedpath;
                    path           = checkBox1.Text;
                    streamr.Close();

                    if (path != null)
                    {
                        textBox1.Text = path;
                        button2.Select();
                    }
                }
                else
                {
                    MessageBox.Show("Path Information is Missing");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #4
0
        private void button10_Click(object sender, EventArgs e)//decrypt aes
        {
            //string text = testtextbox.Text;
            string decrypted = AesCrypt.Decrypt(testtextbox.Text);

            testtextbox.Text = decrypted;
        }
Пример #5
0
        private void btn_Login_Click(object sender, RoutedEventArgs e)
        {
            if (txt_pass.Password == null || txt_user.Text == null)
            {
                MessageBox.Show("Please enter username or password");
            }
            else
            {
                string usr = txt_user.Text;

                if (!Directory.Exists("Data\\" + usr))
                {
                    tb_Logfail.Visibility = Visibility.Visible;
                }
                else
                {
                    var sr = new StreamReader("Data\\" + usr + "\\Data.ls");

                    string ecUser = sr.ReadLine();
                    string ecPass = sr.ReadLine();
                    sr.Close();

                    string dcUser = AesCrypt.Decrypt(ecUser);
                    string dcPass = AesCrypt.Decrypt(ecPass);

                    if (dcUser == txt_user.Text && dcPass == txt_pass.Password)
                    {
                        MessageBox.Show("Welcome " + txt_user.Text);
                    }
                }
            }
        }
Пример #6
0
        private void btn_Apply_Click(object sender, RoutedEventArgs e)
        {
            if (textUsername.Text.Length < 3 || passwordBox.Password.Length < 5)
            {
                MessageBox.Show("Username or Password is invalid");
            }
            else
            {
                Directory.CreateDirectory("data\\");

                var sw = new StreamWriter("data\\data.ls");

                var encusr  = AesCrypt.Encrypt(textUsername.Text);
                var encpass = AesCrypt.Encrypt(passwordBox.Password);

                sw.WriteLine(encusr);
                sw.WriteLine(encpass);
                sw.Close();

                MessageBox.Show(String.Format("User {0} configuration was successfully saved.", textUsername.Text));

                var sr = new StreamReader("data\\data.ls");

                var r_encusr  = sr.ReadLine();
                var r_encpass = sr.ReadLine();
                sr.Close();

                decusr  = AesCrypt.Decrypt(r_encusr);
                decpass = AesCrypt.Decrypt(r_encpass);

                textUsername.Text    = decusr;
                textPassword.Text    = decpass;
                passwordBox.Password = decpass;
            }

            var MyIni = new IniFile("Settings.ini");

            System.Windows.Controls.TextBox[] textboxes = { textSat, textSun, textMon, textTue, textWed, textThur, textFri };
            for (int i = 0; i < settingday.Length; i++)
            {
                MyIni.Write(settingday[i], textboxes[i].Text, "Week");
            }
            if (comboBrowser.SelectedIndex == 1)
            {
                MyIni.Write("Wait Time", textWaittime.Text, "Wait Time");
            }

            MyIni.Write("Browser", comboBrowser.SelectedItem.ToString(), "Browser Choice");
            MyIni.Write("Security", comboSecurity.SelectedItem.ToString(), "Security Choice");
            MyIni.Write("ManualSubmit", fridayCheckBox.IsChecked.ToString(), "Submit");
            MyIni.Write("CloseBrowser", ChkCloseAfterUpdate.IsChecked.ToString(), "Check");
            securitychoice = MyIni.Read("Security", "Security Choice");
            browserchoice  = MyIni.Read("Browser", "Browser Choice");
            browserclose   = MyIni.Read("CloseBrowser", "Check");
            //Once apply is clicked write true to the settings.ini file and then read it into our public string of appliedcheck so that when start checks it will allow it through
            MyIni.Write("Applied", "True", "Check");
            appliedcheck = MyIni.Read("Applied", "Check");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (Pass_textBox.Text == "")
            {
                MessageBox.Show("Password is Empty");
            }
            else
            {
                string dir     = "Userdata";
                var    streamr = new StreamReader("data\\" + dir + "\\data.ls");


                string encpass = streamr.ReadLine();
                streamr.Close();


                string decpass = AesCrypt.Decrypt(encpass);

                if (decpass == textBox1.Text)
                {
                    if (Pass_textBox.Text.Length < 4)
                    {
                        MessageBox.Show("Password is Invaled or too short!");
                    }
                    else
                    {
                        string dir1 = "Userdata";
                        Directory.CreateDirectory("data\\" + dir1);

                        var streamw = new StreamWriter("data\\" + dir1 + "\\data.ls");

                        string w_encpass = AesCrypt.Encrypt(Pass_textBox.Text);

                        streamw.WriteLine(w_encpass);
                        streamw.Close();

                        MessageBox.Show("Password Successfully Changed.");
                        Pass_textBox.Clear();
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Password Not Matched!");
                    textBox1.Clear();
                }
            }
        }
Пример #8
0
        public string getUsrName()
        {
            string dir   = user;
            string error = "USER NOT FOUND !";

            if (!Directory.Exists("data\\" + dir))
            {
                return(error);
            }
            else
            {
                var    sr4            = new StreamReader("data\\" + dir + "\\mail.ls");
                string cryptedMailUsr = sr4.ReadLine();
                sr4.Close();
                string decryptedMailUsr = AesCrypt.Decrypt(cryptedMailUsr);
                return(decryptedMailUsr);
            }
        }
Пример #9
0
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                try
                {
                    if (textBox1.Text == "")
                    {
                        MessageBox.Show("Password is Empty");
                        textBox1.Clear();
                    }
                    else
                    {
                        string dir     = "Userdata";
                        var    streamr = new StreamReader("data\\" + dir + "\\data.ls");


                        string encpass = streamr.ReadLine();
                        streamr.Close();


                        string decpass = AesCrypt.Decrypt(encpass);

                        if (decpass == textBox1.Text)
                        {
                            Code form = new Code();
                            form.Show();
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("Password Not Set!");
                            textBox1.Clear();
                        }
                    }
                }

                catch (Exception)
                {
                    MessageBox.Show("Password is Incorrect!");
                    textBox1.Clear();
                }
            }
        }
Пример #10
0
        public MainWindow()
        {
            AutoUpdater.RunUpdateAsAdmin = true;
            AutoUpdater.Start("http://162.217.248.211/etes/Updater.xml");

            InitializeComponent();
            AppWindow = this;
            Notification.CreateNotify();
            Scheduler sc = new Scheduler();

            sc.Start();


            if (File.Exists("data\\data.ls"))
            {
                var sr = new StreamReader("data\\data.ls");

                string encusr  = sr.ReadLine();
                string encpass = sr.ReadLine();
                sr.Close();

                decusr  = AesCrypt.Decrypt(encusr);
                decpass = AesCrypt.Decrypt(encpass);

                textUsername.Text    = decusr;
                textPassword.Text    = decpass;
                passwordBox.Password = decpass;
            }
            else
            {
                MessageBox.Show("Ensure you fill out the login and password details and Apply.");
                Visibility = Visibility.Visible;
            }

            if (!File.Exists("Settings.ini"))
            {
                //Create new Settings.ini file
                var MyIni = new IniFile("Settings.ini");

                //Set default values for days of the week
                MyIni.Write("Saturday", "", "Week");
                MyIni.Write("Sunday", "", "Week");
                MyIni.Write("Monday", "7.50", "Week");
                MyIni.Write("Tuesday", "7.50", "Week");
                MyIni.Write("Wednesday", "7.50", "Week");
                MyIni.Write("Thursday", "7.50", "Week");
                MyIni.Write("Friday", "7.50", "Week");
                MyIni.Write("WorkOrder", "1010 REGULAR HOURS", "WorkOrder");
                MyIni.Write("Wait Time", "15", "Wait Time");
                MyIni.Write("Browser", "System.Windows.Controls.ComboBoxItem: Chrome", "Browser Choice");
                MyIni.Write("Security", "System.Windows.Controls.ComboBoxItem: VIP App (PC)", "Security Choice");
                MyIni.Write("ManualSubmit", "False", "Submit");
                MyIni.Write("Reminded", "False", "Reminders"); //sets notifyicon to ignore or send the info message about closing from the notification area.
                MyIni.Write("Applied", "False", "Check");      //checks that user has applied their data before starting browser
                MyIni.Write("SalesForce", "False", "Check");   //sets salesforce autologin option at setting.ini creation (off by default)
                MyIni.Write("CloseBrowser", "False", "Check"); //sets whether to close the browser after updating the timesheet or not.  (off by default)


                //Set variables with Settings.ini values
                //string[] settingday = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
                //TextBox[] textboxes = { textMon, textTue, textWed, textThur, textFri, textSat, textSun };
                System.Windows.Controls.TextBox[] textboxes = { textSat, textSun, textMon, textTue, textWed, textThur, textFri };
                for (int i = 0; i < settingday.Length; i++)
                {
                    textboxes[i].Text = MyIni.Read(settingday[i], "Week");
                }
                textWaittime.Text = (MyIni.Read("Wait Time", "Wait Time"));

                var browserchoice = MyIni.Read("Browser", "Browser Choice");
                if (browserchoice == "System.Windows.Controls.ComboBoxItem: Chrome")
                {
                    comboBrowser.SelectedIndex = 0;
                }
                else
                {
                    comboBrowser.SelectedIndex = 1;
                }

                var securitychoice = MyIni.Read("Security", "Security Choice");
                if (securitychoice == "System.Windows.Controls.ComboBoxItem: VIP App (PC)")
                {
                    comboSecurity.SelectedIndex = 0;
                }
                else
                {
                    comboSecurity.SelectedIndex = 1;
                }

                //Check if the Submit on Friday checkbox is checked or not and apply the correct check against the check object
                fridaycheck = MyIni.Read("ManualSubmit", "Submit");
                if (fridaycheck == "True")
                {
                    fridayCheckBox.IsChecked = true;
                }
                else
                {
                    fridayCheckBox.IsChecked = false;
                }

                //Check if the Close Browser checkbox is checked or not and apply the correct check against the check object
                browserclose = MyIni.Read("CloseBrowser", "Check");
                if (browserclose == "True")
                {
                    ChkCloseAfterUpdate.IsChecked = true;
                }
                else
                {
                    ChkCloseAfterUpdate.IsChecked = false;
                }

                //Read the apply check into the variable so that the Start button can run.  This is required so the user cant start it without applying their username and pass.
                var appliedcheck = MyIni.Read("Applied", "Check");

                //Check if we need a wait time box, Firefox needs it, Chrome doesnt
                if (comboBrowser.SelectedIndex == 1)
                {
                    textBWait.Visibility    = Visibility.Visible;
                    textWaittime.Visibility = Visibility.Visible;
                    textBlock8.Visibility   = Visibility.Visible;
                    textWaittime.Text       = (MyIni.Read("Wait Time", "Wait Time"));
                }
                else
                {
                    textBWait.Visibility    = Visibility.Hidden;
                    textWaittime.Visibility = Visibility.Hidden;
                    textBlock8.Visibility   = Visibility.Hidden;
                }
                //Read False into appliedcheck to ensure user cant start the program without applying their config.
                appliedcheck = MyIni.Read("Applied", "Check");
            }
            else
            {
                //Read Settings.ini
                var MyIni = new IniFile("Settings.ini");

                //string[] settingday = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
                //TextBox[] textboxes = { textMon, textTue, textWed, textThur, textFri, textSat, textSun };
                System.Windows.Controls.TextBox[] textboxes = { textSat, textSun, textMon, textTue, textWed, textThur, textFri };
                for (int i = 0; i < settingday.Length; i++)
                {
                    textboxes[i].Text = MyIni.Read(settingday[i], "Week");
                }

                browserchoice = MyIni.Read("Browser", "Browser Choice");
                if (browserchoice == "System.Windows.Controls.ComboBoxItem: Chrome")
                {
                    comboBrowser.SelectedIndex = 0;
                }
                else
                {
                    comboBrowser.SelectedIndex = 1;
                }

                securitychoice = MyIni.Read("Security", "Security Choice");
                if (securitychoice == "System.Windows.Controls.ComboBoxItem: VIP App (PC)")
                {
                    comboSecurity.SelectedIndex = 0;
                }
                else
                {
                    comboSecurity.SelectedIndex = 1;
                }

                var fridaycheck = MyIni.Read("ManualSubmit", "Submit");
                if (fridaycheck == "True")
                {
                    fridayCheckBox.IsChecked = true;
                }
                else
                {
                    fridayCheckBox.IsChecked = false;
                }

                //Check if the Close Browser checkbox is checked or not and apply the correct check against the check object
                var browserclose = MyIni.Read("CloseBrowser", "Check");
                if (browserclose == "True")
                {
                    ChkCloseAfterUpdate.IsChecked = true;
                }
                else
                {
                    ChkCloseAfterUpdate.IsChecked = false;
                }

                //Check if we need a wait time box, Firefox needs it, Chrome doesnt
                if (comboBrowser.SelectedIndex == 1)
                {
                    textBWait.Visibility    = Visibility.Visible;
                    textWaittime.Visibility = Visibility.Visible;
                    textBlock8.Visibility   = Visibility.Visible;
                    textWaittime.Text       = (MyIni.Read("Wait Time", "Wait Time"));
                }
                else
                {
                    textBWait.Visibility    = Visibility.Hidden;
                    textWaittime.Visibility = Visibility.Hidden;
                    textBlock8.Visibility   = Visibility.Hidden;
                }
                //Read the apply check into the variable so that the Start button can run.  This is required so the user cant start it without applying their username and pass.
                var appliedcheck = MyIni.Read("Applied", "Check");
                //Read the Settings.ini file to see if we need to set the checkbox true or false.
                if (MyIni.Read("SalesForce", "Check") == "True")
                {
                    ChkSalesForce.IsChecked = true;
                    //If the checkbox for salesforce is checked, run the salesforce automation schedule.The ?? false is because IsChecked is an interdeminable bool, so it can be true, false, or null.The ?? tells it, if its null then just set it false.
                    //Scheduler sf = new Scheduler();
                    //sf.SFStart();
                }
                else
                {
                    ChkSalesForce.IsChecked = false;
                }
            }
        }
Пример #11
0
        public async Task MakeSessionAsync(string acessToken, string refreshToken = null)
        {
            var rsa = new RsaService();
            var aes = new AesCrypt();

            var rsaPair = rsa.GenerateKeys();

            var strongKeyRequest = new
            {
                publicKey = rsaPair.publicKey
            };

            var authRequest = new AuthRequest(acessToken);

            string strongKeyJsonRequest    = JsonConvert.SerializeObject(strongKeyRequest);
            var    strongKeyRequestMessage = authRequest.BuildRequestMessage(ConfigurationManager.AppSettings.Get("devUrl") + Urls.GetStrongKeyUrl, HttpMethod.Post, strongKeyJsonRequest);

            var strongKeyResponseMessage = await authRequest.httpClient.SendAsync(strongKeyRequestMessage);

            if (strongKeyResponseMessage.StatusCode == HttpStatusCode.NotFound)
            {
                var firstSessionRequestModel = new CreateMessangerSessionRequest()
                {
                    PublicKey = rsaPair.publicKey
                };

                string jsonRequest = JsonConvert.SerializeObject(firstSessionRequestModel);

                var firstSessionResponse = await authRequest.GetStringFromHttpResultAsync(ConfigurationManager.AppSettings.Get("devUrl") + Urls.CreateFirstSessionUrl, HttpMethod.Post, jsonRequest);

                var response = JsonConvert.DeserializeObject <CreateFirstMessangerSessionResponse>(firstSessionResponse);

                string decryptedAesKey = rsa.Decrypt(rsaPair.privateKey, response.CryptedAes);

                byte[] decryptedAesKeyBuffer = decryptedAesKey.FromUrlSafeBase64();

                await userProvider.CreateStrongKeyAsync(UserId, decryptedAesKeyBuffer);

                string newToken = await tokenService.MakeAuthTokenAsync(UserId, true);

                authRequest = new AuthRequest(newToken);

                rsaPair = rsa.GenerateKeys();

                string cryptedPublicKey    = aes.Crypt(decryptedAesKeyBuffer.ToUrlSafeBase64(), rsaPair.publicKey);
                var    sessionRequestModel = new CreateMessangerSessionRequest()
                {
                    PublicKey = cryptedPublicKey
                };

                jsonRequest = JsonConvert.SerializeObject(sessionRequestModel);

                var httpRequest     = authRequest.BuildRequestMessage(ConfigurationManager.AppSettings.Get("devUrl") + Urls.CreateSessionUrl, HttpMethod.Post, jsonRequest);
                var sessionResponse = await authRequest.httpClient.SendAsync(httpRequest);

                sessionResponse.EnsureSuccessStatusCode();

                var    session = JsonConvert.DeserializeObject <CreateMessangerSessionResponse>(await sessionResponse.Content.ReadAsStringAsync());
                string decryptedServerPublicKey = aes.Decrypt(decryptedAesKey, session.ServerPublicKey);
                string decryptedSessionId       = aes.Decrypt(decryptedAesKey, session.SessionId);

                await userProvider.CreateSessionAsync(new Session()
                {
                    ClientPrivateKey = rsaPair.privateKey,
                    ServerPublicKey  = decryptedServerPublicKey,
                    ClientPublicKey  = rsaPair.publicKey,
                    UserId           = UserId,
                    SessionId        = decryptedSessionId
                });
            }
            else if (!string.IsNullOrEmpty(refreshToken) && strongKeyResponseMessage.StatusCode == HttpStatusCode.OK)
            {
                var strongKeyResponse = JsonConvert.DeserializeObject <GetStrongKeyResponse>(
                    await strongKeyResponseMessage.Content.ReadAsStringAsync()
                    );

                var decryptedStrongKey = rsa.Decrypt(rsaPair.privateKey, strongKeyResponse.StrongKey);
                await userProvider.CreateStrongKeyAsync(UserId, decryptedStrongKey.FromUrlSafeBase64());

                rsaPair = rsa.GenerateKeys();
                var cryptedPublicKey = aes.Crypt(decryptedStrongKey, rsaPair.publicKey);

                var sessionRequest = new CreateMessangerSessionRequest()
                {
                    PublicKey = cryptedPublicKey
                };

                string jsonSessionRequest = JsonConvert.SerializeObject(sessionRequest);
                var    sessionResponse    = await authRequest.MakeRequestAsync <CreateMessangerSessionResponse>(ConfigurationManager.AppSettings.Get("devUrl") + Urls.CreateSessionUrl, HttpMethod.Post, jsonSessionRequest);

                string decryptedPublicKey = aes.Decrypt(decryptedStrongKey, sessionResponse.ServerPublicKey);
                string decryptedSessionId = aes.Decrypt(decryptedStrongKey, sessionResponse.SessionId);

                await userProvider.CreateSessionAsync(new Session()
                {
                    ClientPrivateKey = rsaPair.privateKey,
                    ClientPublicKey  = rsaPair.publicKey,
                    ServerPublicKey  = decryptedPublicKey,
                    UserId           = UserId,
                    SessionId        = decryptedSessionId
                });
            }
        }
Пример #12
0
        private void GetMail()
        {
            string mailfrom = logform.getUsrName();
            string mailpass = logform.getUsrPass();

            try {
                Task.Run(() =>
                {
                    using (ImapClient client = new ImapClient("imap.gmail.com", 993, mailfrom, mailpass, AuthMethod.Login, true))
                    {
                        if (client.Supports("IDLE") == false)
                        {
                            MessageBox.Show("Server do not support IMAP IDLE");
                            return;
                        }
                        string cryptedAppSign = AesCrypt.Encrypt("UrfaDiyarbakir");

                        var uids  = client.Search(SearchCondition.Text(cryptedAppSign));
                        int index = 0;


                        foreach (var id in uids)
                        {
                            var m = client.GetMessage(id, FetchOptions.Normal);


                            int a = m.Body.IndexOf("---AppSign---") + "---AppSign---".Length;
                            int b = m.Body.IndexOf("---Username---");

                            int c = m.Body.IndexOf("---Username---") + "---Username---".Length;
                            int d = m.Body.IndexOf("---Body---");

                            int e = m.Body.IndexOf("---Body---") + "---Body---".Length;
                            int f = m.Body.IndexOf("---Sign---");

                            string appsign       = m.Body.Substring(0, m.Body.IndexOf("---AppSign---"));
                            string Username      = AesCrypt.Decrypt(m.Body.Substring(a, b - a));
                            string sign          = m.Body.Substring(e, f - e);
                            string encryptedBody = m.Body.Substring(c, d - c);
                            string dir           = EncryptedMailApp.LoginForm.user;


                            char[] charsToTrim  = { ' ', '"' };
                            string encryptedAES = FbClient.Get(EncryptedMailApp.LoginForm.user + "/friends/" + Username + "/aes").Body.ToString().Trim(charsToTrim);
                            string friendPublic = FbClient.Get(EncryptedMailApp.LoginForm.user + "/friends/" + Username + "/publicKey").Body.ToString().Trim(charsToTrim);
                            string aes;
                            string decryptedBody;
                            string decryptedSubject;
                            try
                            {
                                string decryptetaes = RSAobj.Decrypt(encryptedAES);
                                aes = decryptetaes;
                            }
                            catch
                            {
                                aes = null;
                                Console.WriteLine("error on decrypting aes ");
                            }
                            try
                            {
                                decryptedBody = AesCrypt.DecryptParam(encryptedBody, aes);
                            }
                            catch
                            {
                                decryptedBody = null;
                                Console.WriteLine("error on decrpting body");
                            }
                            try
                            {
                                decryptedSubject = AesCrypt.DecryptParam(m.Subject, aes);
                            }
                            catch
                            {
                                decryptedSubject = null;
                                Console.WriteLine("error on decrpting subject");
                            }
                            if (RSAobj.VerifySign(decryptedBody, sign, friendPublic) == true)
                            {
                                Console.WriteLine("match");
                                signed = true;
                            }
                            else
                            {
                                Console.WriteLine("missmatch");
                                signed = false;
                            }

                            if (messages[index, 0] == null)
                            {
                                messages[index, 0] = Username;
                                messages[index, 1] = decryptedSubject;
                                messages[index, 2] = decryptedBody;
                            }

                            listBox1.Items.Add(new ListItem {
                                Name = "From:   " + Username + "   Subject:   " + decryptedSubject, Value = index.ToString()
                            });

                            index++;

                            foreach (Attachment attachment in m.Attachments)
                            {
                                byte[] allBytes = new byte[attachment.ContentStream.Length];
                                int bytesread   = attachment.ContentStream.Read(allBytes, 0, (int)attachment.ContentStream.Length);
                                if (System.IO.Directory.Exists("data\\" + dir + "\\attachments") == false)
                                {
                                    System.IO.Directory.CreateDirectory("data\\" + dir + "\\attachments");
                                }
                                string destinationFile = "data\\" + dir + "\\attachments\\" + attachment.Name;
                                BinaryWriter writer    = new BinaryWriter(new FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None));
                                writer.Write(allBytes);
                                writer.Close();
                                if (attachment.Name.EndsWith("crp"))
                                {
                                    EncryptedMailApp.CryptoStuff.DecryptFile(password, destinationFile, destinationFile.Replace("crp", ""));
                                }
                                //MessageBox.Show("saved attachment at attachments, attachment count is : "+ m.Attachments.Count);
                            }
                        }

                        this.listBox1.MouseDoubleClick += new MouseEventHandler(listBox1_MouseDoubleClick);
                    }
                });
            }
            catch (InvalidCredentialsException)
            {
                MessageBox.Show("The server rejected the supplied credentials.");
            }
        }
Пример #13
0
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                string dir     = "UserCode";
                var    streamr = new StreamReader("data\\" + dir + "\\data.ls");

                string Code1  = streamr.ReadLine();
                string Code2  = streamr.ReadLine();
                string Code3  = streamr.ReadLine();
                string Code4  = streamr.ReadLine();
                string Code5  = streamr.ReadLine();
                string Code6  = streamr.ReadLine();
                string Code7  = streamr.ReadLine();
                string Code8  = streamr.ReadLine();
                string Code9  = streamr.ReadLine();
                string Code10 = streamr.ReadLine();
                string Code11 = streamr.ReadLine();
                string Code12 = streamr.ReadLine();

                streamr.Close();

                string decCode1  = AesCrypt.Decrypt(Code1);
                string decCode2  = AesCrypt.Decrypt(Code2);
                string decCode3  = AesCrypt.Decrypt(Code3);
                string decCode4  = AesCrypt.Decrypt(Code4);
                string decCode5  = AesCrypt.Decrypt(Code5);
                string decCode6  = AesCrypt.Decrypt(Code6);
                string decCode7  = AesCrypt.Decrypt(Code7);
                string decCode8  = AesCrypt.Decrypt(Code8);
                string decCode9  = AesCrypt.Decrypt(Code9);
                string decCode10 = AesCrypt.Decrypt(Code10);
                string decCode11 = AesCrypt.Decrypt(Code11);
                string decCode12 = AesCrypt.Decrypt(Code12);

                int code_Hour1  = 6;
                int code_Hour2  = 7;
                int code_Hour3  = 8;
                int code_Hour4  = 9;
                int code_Hour5  = 10;
                int code_Hour6  = 11;
                int code_Hour7  = 12;
                int code_Hour8  = 13;
                int code_Hour9  = 14;
                int code_Hour10 = 15;
                int code_Hour11 = 16;
                int code_Hour12 = 17;


                try
                {
                    if (DateTime.Now.Hour == code_Hour1)//Time 6 hour
                    {
                        if (decCode1 == textBox1.Text)
                        {
                            Main form = new Main();
                            form.Show();
                            this.Hide();
                        }
                    }
                    else
                    {
                        if (DateTime.Now.Hour == code_Hour2)//Time 7 hour
                        {
                            if (decCode2 == textBox1.Text)
                            {
                                Main form = new Main();
                                form.Show();
                                this.Hide();
                            }
                        }
                        else
                        {
                            if (DateTime.Now.Hour == code_Hour3)//Time 8 hour
                            {
                                if (decCode3 == textBox1.Text)
                                {
                                    Main form = new Main();
                                    form.Show();
                                    this.Hide();
                                }
                            }
                            else
                            {
                                if (DateTime.Now.Hour == code_Hour4)//Time 9 hour
                                {
                                    if (decCode4 == textBox1.Text)
                                    {
                                        Main form = new Main();
                                        form.Show();
                                        this.Hide();
                                    }
                                }
                                else
                                {
                                    if (DateTime.Now.Hour == code_Hour5)//Time 10 hour
                                    {
                                        if (decCode5 == textBox1.Text)
                                        {
                                            Main form = new Main();
                                            form.Show();
                                            this.Hide();
                                        }
                                    }
                                    else
                                    {
                                        if (DateTime.Now.Hour == code_Hour6)//Time 11 hour
                                        {
                                            if (decCode6 == textBox1.Text)
                                            {
                                                Main form = new Main();
                                                form.Show();
                                                this.Hide();
                                            }
                                        }
                                        else
                                        {
                                            if (DateTime.Now.Hour == code_Hour7)//Time 12 hour
                                            {
                                                if (decCode7 == textBox1.Text)
                                                {
                                                    Main form = new Main();
                                                    form.Show();
                                                    this.Hide();
                                                }
                                            }
                                            else
                                            {
                                                if (DateTime.Now.Hour == code_Hour8)//Time 13 hour
                                                {
                                                    if (decCode8 == textBox1.Text)
                                                    {
                                                        Main form = new Main();
                                                        form.Show();
                                                        this.Hide();
                                                    }
                                                }
                                                else
                                                {
                                                    if (DateTime.Now.Hour == code_Hour9)//Time 14 hour
                                                    {
                                                        if (decCode9 == textBox1.Text)
                                                        {
                                                            Main form = new Main();
                                                            form.Show();
                                                            this.Hide();
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (DateTime.Now.Hour == code_Hour10)//Time 15 hour
                                                        {
                                                            if (decCode10 == textBox1.Text)
                                                            {
                                                                Main form = new Main();
                                                                form.Show();
                                                                this.Hide();
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (DateTime.Now.Hour == code_Hour11)//Time 16 hour
                                                            {
                                                                if (decCode11 == textBox1.Text)
                                                                {
                                                                    Main form = new Main();
                                                                    form.Show();
                                                                    this.Hide();
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (DateTime.Now.Hour == code_Hour12)//Time 17 hour
                                                                {
                                                                    if (decCode12 == textBox1.Text)
                                                                    {
                                                                        Main form = new Main();
                                                                        form.Show();
                                                                        this.Hide();
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    MessageBox.Show("Incorrect Code!");
                                                                    textBox1.Clear();
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                catch (Exception)
                {
                    MessageBox.Show("Incorrect Code!ByTime");
                    //throw ex;
                }
            }
        }
Пример #14
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            if (usrname.Text.Length < 3 || usrpass.Text.Length < 3)
            {
                MessageBox.Show("Username or Password is invalid");
            }
            else
            {
                string dir = usrname.Text;
                user = usrname.Text;

                if (!Directory.Exists("data\\" + dir))
                {
                    MessageBox.Show("user not found" + dir);
                }
                else
                {
                    var    sr          = new StreamReader("data\\" + dir + "\\data.ls");
                    string cryptedusr  = sr.ReadLine();
                    string cryptedpass = sr.ReadLine();
                    sr.Close();
                    string decryptedusr  = AesCrypt.Decrypt(cryptedusr);
                    string decryptedpass = AesCrypt.Decrypt(cryptedpass);

                    var sr2 = new StreamReader("data\\" + dir + "\\PublicKey.ls");

                    string readedKey = sr2.ReadToEnd();
                    RSAobj.PublicKey = readedKey;
                    userpublicKey    = readedKey;

                    sr2.Close();

                    var sr3 = new StreamReader("data\\" + dir + "\\PrivateKey.ls");

                    string readedKey2 = sr3.ReadToEnd();
                    RSAobj.PrivateKey = readedKey2;

                    sr3.Close();

                    var sr4 = new StreamReader("data\\" + dir + "\\mail.ls");

                    string readedMail    = sr4.ReadLine();
                    string decryptedMail = AesCrypt.Decrypt(readedMail);
                    mail = decryptedMail;

                    sr4.Close();

                    if (decryptedusr == usrname.Text && decryptedpass == usrpass.Text)
                    {
                        MessageBox.Show("Authentication succesfull.");
                        Form1 log = new Form1();
                        log.Show();
                    }
                    else
                    {
                        MessageBox.Show("User or password is wrong.");
                        failTime++;
                        if (failTime > 10)
                        {
                            if (Directory.Exists("data\\" + dir))
                            {
                                File.Delete("data\\" + dir + "\\data.ls");
                                File.Delete("data\\" + dir + "\\mail.ls");
                                File.Delete("data\\" + dir + "\\PrivateKey.ls");
                                File.Delete("data\\" + dir + "\\PublicKey.ls");
                                Directory.Delete("data\\" + dir);
                                MessageBox.Show("Your account is deleted do not brute-force xd");
                            }
                        }
                    }
                }
            }
        }
Пример #15
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (usrTxt.Text.Length < 3 || passTxt.Text.Length < 5)
            {
                MessageBox.Show("نام کاربر یا رمز عبور اشتباه یا کوتاه است");
            }
            else
            {
                string usrchk  = AesCrypt.Encrypt(usrTxt.Text);
                string passchk = AesCrypt.Encrypt(passTxt.Text);
                DataAccess.RunQuery("Select * From Operators where Username= '******'");
                int i = DataAccess.Dataset.Tables[0].Rows.Count;


                string dir = usrTxt.Text;


                if (i <= 0)
                {
                    MessageBox.Show(" در سیستم موجود نیست " + dir + " کاربر");
                }
                else
                {
                    DataAccess.cmd = new SqlCommand("select * from Operators where Username = @username and Password = @password", DataAccess.con);
                    DataAccess.cmd.Parameters.AddWithValue("@username", usrchk);
                    DataAccess.cmd.Parameters.AddWithValue("@password", passchk);
                    DataAccess.con.Open();

                    DataAccess.Dataset = new DataSet();
                    DataAccess.SQLDA   = new SqlDataAdapter(DataAccess.cmd);
                    DataAccess.SQLDA.Fill(DataAccess.Dataset);
                    DataAccess.con.Close();


                    bool loginSuccessful = ((DataAccess.Dataset.Tables.Count > 0) && (DataAccess.Dataset.Tables[0].Rows.Count > 0));

                    if (loginSuccessful == true)
                    {
                        decusr  = AesCrypt.Decrypt(usrchk);
                        decpass = AesCrypt.Decrypt(passchk);
                    }



                    if (decusr == usrTxt.Text && decpass == passTxt.Text)
                    {
                        DataAccess.con.Close();
                        MessageBox.Show("خوش آمدید" + " داخل سیستم " + decusr);

                        chkup = true;
                    }
                    else
                    {
                        MessageBox.Show("نام کاربر یا رمز عبور اشتباه است");
                    }
                    if (chkup == true)
                    {
                        MainForm MF = new MainForm();
                        MF.Show();
                        Login_System_Encrypted lf = new Login_System_Encrypted();
                        this.Visible = false;
                    }
                }
            }
        }