static void Main() { // SpreadsheetInfo.SetLicense("EQU2-1000-0000-000U"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.DoEvents(); bool bInitiallyOwnd = true; bool bIsCreated = true; Mutex m = new Mutex(bInitiallyOwnd, Application.ProductName, out bIsCreated); if (!(bInitiallyOwnd && bIsCreated)) { Application.Exit(); } else { MyChecker checker = new MyChecker(); checker.IsAuthorizedbyAuthorizationFile("c:\\1.key"); if (false) { MessageBox.Show("软件未授权。\n即将退出。", "提示"); return; } Application.Run(new Form1()); m.ReleaseMutex(); } }
//Create new account private void btSignIn_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(MyConnect.getString("select Email from LogIn where Email=N'" + txNewEmail.Text + "'"))) { MyChecker.setErr(txNewEmail, errorEmail, "Email Invailable!", Properties.Resources.ERROR); email = false; txNewEmail.Focus(); return; } if (!username) { txNewUserName.Focus(); return; } else if (!email) { txNewEmail.Focus(); return; } else if (!password) { txNewPassword.Focus(); return; } else if (!confirompw) { txConfiromPw.Focus(); return; } else { if (ac.AddObject(new Account(txNewUserName.Text, StringPassword.EncrytString(txNewPassword.Text, Properties.Resources.KeyCrypt), cbManager.Checked, txNewEmail.Text))) { MessageBox.Show("Create new account successfully!"); } else { MessageBox.Show("Can't create account!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } setAutoCompleteCollection(); } }
//TextChanged private void txUserName_TextChanged(object sender, EventArgs e) { if (String.IsNullOrEmpty(txUserName.Text)) { MyChecker.setErr(txUserName, errorUserName, "Please enter username!", Properties.Resources.ERROR); lbErrorLogIn.Visible = false; } else { errorUserName.Clear(); } }
private void txPassword_TextChanged(object sender, EventArgs e) { errorPassword.Icon = Properties.Resources.ERROR; if (String.IsNullOrEmpty(txPassword.Text)) { MyChecker.setErr(txPassword, errorPassword, "Please enter password!", Properties.Resources.ERROR); lbErrorLogIn.Visible = false; } else { errorPassword.Clear(); } }
//Text Change private void txCurrPassword_TextChanged(object sender, EventArgs e) { if (String.IsNullOrEmpty(txCurrPassword.Text)) { MyChecker.setErr(txCurrPassword, errorCur, "Enter your password", Properties.Resources.ERROR); curr = false; } else if (!txCurrPassword.Text.Equals(StringPassword.DecrytString(account.password, Properties.Resources.KeyCrypt))) { errorCur.Clear(); curr = false; } else { curr = true; errorCur.Clear(); } }
private void txConfirmPasswrod_TextChanged(object sender, EventArgs e) { if (String.IsNullOrEmpty(txConfirmPasswrod.Text)) { MyChecker.setErr(txConfirmPasswrod, errorRe, "Enter your password", Properties.Resources.ERROR); confirm = false; } else if (!txConfirmPasswrod.Text.Equals(txNewPassword.Text)) { MyChecker.setErr(txConfirmPasswrod, errorRe, "Password is not match!", Properties.Resources.ERROR); confirm = false; } else { MyChecker.setErr(txConfirmPasswrod, errorRe, "Available!", Properties.Resources.OK); confirm = true; } }
private void txReEnterPw_TextChanged(object sender, EventArgs e) { if (String.IsNullOrEmpty(txReEnterPw.Text)) { confirompw = false; return; } else if (txReEnterPw.Text.Equals(txForgetPw.Text) && !String.IsNullOrEmpty(txReEnterPw.Text)) { MyChecker.setErr(txReEnterPw, errorConfiromPw, "Available!", Properties.Resources.OK); confirompw = true; } else { MyChecker.setErr(txReEnterPw, errorConfiromPw, "Password do not match", Properties.Resources.ERROR); confirompw = false; } }
//Log in private void btLogin_Click(object sender, EventArgs e) { errorUserName.Icon = Properties.Resources.ERROR; errorPassword.Icon = Properties.Resources.ERROR; if (String.IsNullOrEmpty(txUserName.Text)) { errorUserName.SetError(txUserName, "Please enter user name!!"); //check textbox username } else { errorUserName.SetError(txUserName, null); } if (String.IsNullOrEmpty(txPassword.Text)) { errorPassword.SetError(txPassword, "Please enter password!!"); //check textbox password } else { errorUserName.SetError(txPassword, null); } if (!String.IsNullOrEmpty(txUserName.Text) && !String.IsNullOrEmpty(txPassword.Text)) { if (MyChecker.checkUserName(txUserName.Text) && MyChecker.checkPassword(txUserName.Text, txPassword.Text)) { MessageBox.Show("Log In successfully!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); lbErrorLogIn.Visible = false; if (cbRemember.Checked) { //save user name and password in setting file string key = Properties.Resources.KeyCrypt; Properties.Settings.Default.UserName = StringPassword.EncrytString(txUserName.Text, key); Properties.Settings.Default.Password = StringPassword.EncrytString(txPassword.Text, key); Properties.Settings.Default.Save(); } //Useris accessing Properties.Settings.Default.Accessing = txUserName.Text; Properties.Settings.Default.Service = ac.getObject(txUserName.Text).service; Properties.Settings.Default.Save(); this.Hide(); frmMain main = new frmMain(); main.setUserAccessing("User is accessing : " + txUserName.Text); main.Show(); } else { lbErrorLogIn.Visible = true; } } }
private void txConfiromPw_TextChanged(object sender, EventArgs e) { btSignIn.Enabled = checkNotEmptyOrNull(); if (String.IsNullOrEmpty(txConfiromPw.Text)) { confirompw = false; return; } else if (txConfiromPw.Text.Equals(txNewPassword.Text) && !String.IsNullOrEmpty(txConfiromPw.Text)) { MyChecker.setErr(txConfiromPw, errorConfiromPw, "Available!", Properties.Resources.OK); confirompw = true; } else { MyChecker.setErr(txConfiromPw, errorConfiromPw, "Password do not match", Properties.Resources.ERROR); confirompw = false; } }
//TextChanged private void txNewUserName_TextChanged(object sender, EventArgs e) { btSignIn.Enabled = checkNotEmptyOrNull(); if (String.IsNullOrEmpty(txNewUserName.Text)) { username = false; return; } else if (MyChecker.checkUserName(txNewUserName.Text)) { MyChecker.setErr(txNewUserName, errorUserName, "User name alreader exists!", Properties.Resources.ERROR); username = false; } else { MyChecker.setErr(txNewUserName, errorUserName, "Available!", Properties.Resources.OK); username = true; } }
private void txNewEmail_TextChanged(object sender, EventArgs e) { var temp = sender as TextBox; btSignIn.Enabled = checkNotEmptyOrNull(); if (String.IsNullOrEmpty(temp.Text)) { email = false; return; } else if (!MyChecker.isEmail(temp.Text)) { MyChecker.setErr(temp, errorEmail, "Email Invailable!", Properties.Resources.ERROR); email = false; } else { MyChecker.setErr(temp, errorEmail, "Available!", Properties.Resources.OK); email = true; } }
private void txNewPassword_TextChanged(object sender, EventArgs e) { var temp = sender as TextboxPassword; if (String.IsNullOrEmpty(temp.Text)) { curr = false; } else if (MyChecker.HaveUnicodeCharacter(temp.Text)) { MyChecker.setErr(temp, errorNew, "Can't accept password with a unicode character. Please try again!!", Properties.Resources.ERROR); newpw = false; } else if (!MyChecker.isPassword(temp.Text)) { MyChecker.setErr(temp, errorNew, "Password need a-z, A-Z, 0-9 and symbol for a stronger password!", Properties.Resources.ERROR); newpw = false; } else { MyChecker.setErr(temp, errorNew, "Available!", Properties.Resources.OK); newpw = true; } }
private void btSend_Click(object sender, EventArgs e) { code = StringPassword.RandomStringGenerator(6); account = (ac.getObject(ac.getUserName(txSendEmail.Text))); if (String.IsNullOrEmpty(txSendEmail.Text)) { return; } if (String.IsNullOrEmpty(account.username)) { MyChecker.setErr(txSendEmail, errorEmail, "Email is not available!", Properties.Resources.ERROR); txSendEmail.Focus(); } else if (MyAction.sendEmail(txSendEmail.Text, code)) { MessageBox.Show("If you don't received code, Please try send again!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); myEmail = txSendEmail.Text; } else { MessageBox.Show("If you don't received code, Please try send again!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); txSendEmail.Focus(); } groupBox1.Visible = false; }
public frmAccountSetting() { InitializeComponent(); //Text Change txChangeEmail.TextChanged += (o, e) => { var temp = o as TextBox; if (!MyChecker.isEmail(temp.Text)) { MyChecker.setErr(temp, errorChangeEmail, "Email Invailable!", Properties.Resources.ERROR); return; } else { MyChecker.setErr(temp, errorChangeEmail, "Available!", Properties.Resources.OK); btChangeEmail.Enabled = true; } }; //Button Click btChangeEmail.Click += (o, e) => { frmEnterPassword frmPasswrod = new frmEnterPassword(btChangeEmail, txChangeEmail); frmPasswrod.ShowDialog(); }; }
//Button save private void btSaveShange_Click(object sender, EventArgs e) { if (!curr) { txCurrPassword.Focus(); MyChecker.setErr(txCurrPassword, errorCur, "Wrong passowrd!", Properties.Resources.ERROR); return; } if (!newpw) { txNewPassword.Focus(); return; } if (!confirm) { txConfirmPasswrod.Focus(); return; } account.password = StringPassword.EncrytString(txNewPassword.Text, Properties.Resources.KeyCrypt); if (new AccountDAO().UpdateObject(account)) { MessageBox.Show("Password saved!", "Infomation", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("There was an error, can't save password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public frmEnterPassword(Button btChangeEmail, TextBox txChangeEmail) { InitializeComponent(); txPassword.TextChanged += (o, e) => { if (!String.IsNullOrEmpty(txPassword.Text)) { btOk.Enabled = true; } else { btOk.Enabled = false; MyChecker.setErr(txPassword, errorPassword, "Please enter password!", Properties.Resources.ERROR); } }; btOk.Click += (o, e) => { if (txPassword.Text.Equals(StringPassword.DecrytString(account.password, Properties.Resources.KeyCrypt))) { account.email = txChangeEmail.Text; if (new AccountDAO().UpdateObject(account)) { MessageBox.Show("Successfully!", "Informaation", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error, Check your Email again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } btChangeEmail.Enabled = false; this.Close(); } else { MyChecker.setErr(txPassword, errorPassword, "Passwrod is not avalibale!", Properties.Resources.ERROR); } }; }
public override void PerformTest() { X509CertificateParser certParser = new X509CertificateParser(); X509CrlParser crlParser = new X509CrlParser(); // initialise CertStore X509Certificate rootCert = certParser.ReadCertificate(CertPathTest.rootCertBin); X509Certificate interCert = certParser.ReadCertificate(CertPathTest.interCertBin); X509Certificate finalCert = certParser.ReadCertificate(CertPathTest.finalCertBin); X509Crl rootCrl = crlParser.ReadCrl(CertPathTest.rootCrlBin); X509Crl interCrl = crlParser.ReadCrl(CertPathTest.interCrlBin); IList x509Certs = new ArrayList(); x509Certs.Add(rootCert); x509Certs.Add(interCert); x509Certs.Add(finalCert); IList x509Crls = new ArrayList(); x509Crls.Add(rootCrl); x509Crls.Add(interCrl); // CollectionCertStoreParameters ccsp = new CollectionCertStoreParameters(list); // CertStore store = CertStore.GetInstance("Collection", ccsp); // X509CollectionStoreParameters ccsp = new X509CollectionStoreParameters(list); IX509Store x509CertStore = X509StoreFactory.Create( "Certificate/Collection", new X509CollectionStoreParameters(x509Certs)); IX509Store x509CrlStore = X509StoreFactory.Create( "CRL/Collection", new X509CollectionStoreParameters(x509Crls)); // NB: Month is 1-based in .NET //DateTime validDate = new DateTime(2008,9,4,14,49,10).ToUniversalTime(); DateTime validDate = new DateTime(2008, 9, 4, 5, 49, 10); //validating path IList certchain = new ArrayList(); certchain.Add(finalCert); certchain.Add(interCert); // CertPath cp = CertificateFactory.GetInstance("X.509").GenerateCertPath(certchain); PkixCertPath cp = new PkixCertPath(certchain); ISet trust = new HashSet(); trust.Add(new TrustAnchor(rootCert, null)); // CertPathValidator cpv = CertPathValidator.GetInstance("PKIX"); PkixCertPathValidator cpv = new PkixCertPathValidator(); PkixParameters param = new PkixParameters(trust); param.AddStore(x509CertStore); param.AddStore(x509CrlStore); param.Date = new DateTimeObject(validDate); MyChecker checker = new MyChecker(); param.AddCertPathChecker(checker); PkixCertPathValidatorResult result = (PkixCertPathValidatorResult) cpv.Validate(cp, param); PkixPolicyNode policyTree = result.PolicyTree; AsymmetricKeyParameter subjectPublicKey = result.SubjectPublicKey; if (checker.GetCount() != 2) { Fail("checker not evaluated for each certificate"); } if (!subjectPublicKey.Equals(finalCert.GetPublicKey())) { Fail("wrong public key returned"); } // // invalid path containing a valid one test // try { // initialise CertStore rootCert = certParser.ReadCertificate(AC_RAIZ_ICPBRASIL); interCert = certParser.ReadCertificate(AC_PR); finalCert = certParser.ReadCertificate(schefer); x509Certs = new ArrayList(); x509Certs.Add(rootCert); x509Certs.Add(interCert); x509Certs.Add(finalCert); // ccsp = new CollectionCertStoreParameters(list); // store = CertStore.GetInstance("Collection", ccsp); // ccsp = new X509CollectionStoreParameters(list); x509CertStore = X509StoreFactory.Create( "Certificate/Collection", new X509CollectionStoreParameters(x509Certs)); // NB: Month is 1-based in .NET validDate = new DateTime(2004,3,21,2,21,10).ToUniversalTime(); //validating path certchain = new ArrayList(); certchain.Add(finalCert); certchain.Add(interCert); // cp = CertificateFactory.GetInstance("X.509").GenerateCertPath(certchain); cp = new PkixCertPath(certchain); trust = new HashSet(); trust.Add(new TrustAnchor(rootCert, null)); // cpv = CertPathValidator.GetInstance("PKIX"); cpv = new PkixCertPathValidator(); param = new PkixParameters(trust); param.AddStore(x509CertStore); param.IsRevocationEnabled = false; param.Date = new DateTimeObject(validDate); result =(PkixCertPathValidatorResult) cpv.Validate(cp, param); policyTree = result.PolicyTree; subjectPublicKey = result.SubjectPublicKey; Fail("Invalid path validated"); } catch (Exception e) { if (e is PkixCertPathValidatorException && e.Message.StartsWith("Could not validate certificate signature.")) { return; } Fail("unexpected exception", e); } }
public override void PerformTest() { X509CertificateParser certParser = new X509CertificateParser(); X509CrlParser crlParser = new X509CrlParser(); // initialise CertStore X509Certificate rootCert = certParser.ReadCertificate(CertPathTest.rootCertBin); X509Certificate interCert = certParser.ReadCertificate(CertPathTest.interCertBin); X509Certificate finalCert = certParser.ReadCertificate(CertPathTest.finalCertBin); X509Crl rootCrl = crlParser.ReadCrl(CertPathTest.rootCrlBin); X509Crl interCrl = crlParser.ReadCrl(CertPathTest.interCrlBin); IList x509Certs = new ArrayList(); x509Certs.Add(rootCert); x509Certs.Add(interCert); x509Certs.Add(finalCert); IList x509Crls = new ArrayList(); x509Crls.Add(rootCrl); x509Crls.Add(interCrl); // CollectionCertStoreParameters ccsp = new CollectionCertStoreParameters(list); // CertStore store = CertStore.GetInstance("Collection", ccsp); // X509CollectionStoreParameters ccsp = new X509CollectionStoreParameters(list); IX509Store x509CertStore = X509StoreFactory.Create( "Certificate/Collection", new X509CollectionStoreParameters(x509Certs)); IX509Store x509CrlStore = X509StoreFactory.Create( "CRL/Collection", new X509CollectionStoreParameters(x509Crls)); // NB: Month is 1-based in .NET //DateTime validDate = new DateTime(2008,9,4,14,49,10).ToUniversalTime(); DateTime validDate = new DateTime(2008, 9, 4, 5, 49, 10); //validating path IList certchain = new ArrayList(); certchain.Add(finalCert); certchain.Add(interCert); // CertPath cp = CertificateFactory.GetInstance("X.509").GenerateCertPath(certchain); PkixCertPath cp = new PkixCertPath(certchain); ISet trust = new HashSet(); trust.Add(new TrustAnchor(rootCert, null)); // CertPathValidator cpv = CertPathValidator.GetInstance("PKIX"); PkixCertPathValidator cpv = new PkixCertPathValidator(); PkixParameters param = new PkixParameters(trust); param.AddStore(x509CertStore); param.AddStore(x509CrlStore); param.Date = new DateTimeObject(validDate); MyChecker checker = new MyChecker(); param.AddCertPathChecker(checker); PkixCertPathValidatorResult result = (PkixCertPathValidatorResult)cpv.Validate(cp, param); PkixPolicyNode policyTree = result.PolicyTree; AsymmetricKeyParameter subjectPublicKey = result.SubjectPublicKey; if (checker.GetCount() != 2) { Fail("checker not evaluated for each certificate"); } if (!subjectPublicKey.Equals(finalCert.GetPublicKey())) { Fail("wrong public key returned"); } IsTrue(result.TrustAnchor.TrustedCert.Equals(rootCert)); // try a path with trust anchor included. certchain.Clear(); certchain.Add(finalCert); certchain.Add(interCert); certchain.Add(rootCert); cp = new PkixCertPath(certchain); cpv = new PkixCertPathValidator(); param = new PkixParameters(trust); param.AddStore(x509CertStore); param.AddStore(x509CrlStore); param.Date = new DateTimeObject(validDate); checker = new MyChecker(); param.AddCertPathChecker(checker); result = (PkixCertPathValidatorResult)cpv.Validate(cp, param); IsTrue(result.TrustAnchor.TrustedCert.Equals(rootCert)); // // invalid path containing a valid one test // try { // initialise CertStore rootCert = certParser.ReadCertificate(AC_RAIZ_ICPBRASIL); interCert = certParser.ReadCertificate(AC_PR); finalCert = certParser.ReadCertificate(schefer); x509Certs = new ArrayList(); x509Certs.Add(rootCert); x509Certs.Add(interCert); x509Certs.Add(finalCert); // ccsp = new CollectionCertStoreParameters(list); // store = CertStore.GetInstance("Collection", ccsp); // ccsp = new X509CollectionStoreParameters(list); x509CertStore = X509StoreFactory.Create( "Certificate/Collection", new X509CollectionStoreParameters(x509Certs)); // NB: Month is 1-based in .NET //validDate = new DateTime(2004,3,21,2,21,10).ToUniversalTime(); validDate = new DateTime(2004, 3, 20, 19, 21, 10); //validating path certchain = new ArrayList(); certchain.Add(finalCert); certchain.Add(interCert); // cp = CertificateFactory.GetInstance("X.509").GenerateCertPath(certchain); cp = new PkixCertPath(certchain); trust = new HashSet(); trust.Add(new TrustAnchor(rootCert, null)); // cpv = CertPathValidator.GetInstance("PKIX"); cpv = new PkixCertPathValidator(); param = new PkixParameters(trust); param.AddStore(x509CertStore); param.IsRevocationEnabled = false; param.Date = new DateTimeObject(validDate); result = (PkixCertPathValidatorResult)cpv.Validate(cp, param); policyTree = result.PolicyTree; subjectPublicKey = result.SubjectPublicKey; Fail("Invalid path validated"); } catch (Exception e) { if (e is PkixCertPathValidatorException && e.Message.StartsWith("Could not validate certificate signature.")) { return; } Fail("unexpected exception", e); } }