예제 #1
0
        void Validation(bool registration)
        {
            if (txt_login.Text.Trim().Length == 0)
            {
                throw new Exception("Введите логин!");
            }

            if (txt_pass.Password.Length == 0)
            {
                throw new Exception("Введите пароль!");
            }

            if (registration)
            {
                if (Account.CheckAccount(txt_login.Text.Trim()))
                {
                    throw new Exception("Такой пользователь уже есть!");
                }
                else
                {
                    string tempHash = Utility.ByteArrayToString(Cryptography.GetSHA1(txt_pass.Password.Trim()));

                    CurrentData.curAcc = new Account(txt_login.Text.Trim(), tempHash);
                    CurrentData.curAcc.Srlz();

                    using (StreamWriter fs = new StreamWriter(Account.GetAccPath(), true))
                    {
                        fs.WriteLine(txt_login.Text.Trim());
                        fs.WriteLine(tempHash);
                    }
                }
            }
            else
            {
                if (Account.CheckAccount(txt_login.Text.Trim()))
                {
                    if (Account.CheckPassword(txt_login.Text.Trim(), txt_pass.Password.Trim()))
                    {
                        CurrentData.curAcc = new Account(Account.Dsrlz(txt_login.Text.Trim()));
                        Start();
                    }
                    else
                    {
                        throw new Exception("Неправильный пароль!");
                    }
                }
                else
                {
                    throw new Exception("Такого пользователя не существует!");
                }
            }
        }
예제 #2
0
        internal CryptoKey(string publicKey, string privateKey, string name, string ownerAddress,
                           bool purpose)
        {
            this.PublicKey    = publicKey;
            this.PrivateKey   = privateKey;
            this.Name         = name;
            this.OwnerAddress = ownerAddress;
            this.EncrOrSign   = purpose;

            this.Id         = Utility.ByteArrayToHexString(Cryptography.GetSHA1(publicKey));
            this.PublicOnly = PrivateKey == null;
            this.DateTime   = DateTime.Now;
        }
예제 #3
0
 public static bool CheckPassword(string login, string pass)
 {
     if (File.Exists(GetAccPath()))
     {
         string[] allAcc = File.ReadAllLines(GetAccPath());
         for (int i = 0; i < allAcc.Length; i += 2)
         {
             if (allAcc[i] == login)
             {
                 if (allAcc[i + 1] == Utility.ByteArrayToString(Cryptography.GetSHA1(pass)))
                 {
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
         }
         return(false);
     }
     return(false);
 }