Пример #1
0
        public void Update()
        {
            FileStream   fileStream   = null;
            StreamReader streamReader = null;
            StreamWriter streamWrite  = null;

            try
            {
                fileStream   = new FileStream(@"c:\\final\\personalized.txt", FileMode.Open, FileAccess.Read);
                streamReader = new StreamReader(fileStream);
                string[] lines = streamReader.ReadToEnd().Split('\n');
                streamReader.Close();
                if (lines == null)
                {
                    new Error("Personalized File is Empty.");
                    streamReader.Close();
                    fileStream.Close();
                }
                fileStream  = new FileStream(@"c:\\final\\personalized.txt", FileMode.Open, FileAccess.Write);
                streamWrite = new StreamWriter(fileStream);
                foreach (string line in lines)
                {
                    if (String.IsNullOrEmpty(line.Replace("\n", "").Replace("\r", "")))
                    {
                        continue;
                    }
                    string[] splitline = line.Replace("\n", "").Replace("\r", "").Split(',');
                    if (String.Compare(splitline[1], this.accountNumber) == 0)
                    {
                        if (String.Compare(splitline[0], "Personal") == 0)
                        {
                            streamWrite.WriteLine("{0},{1},{2},{3},{4},{5}", splitline[0], splitline[1], splitline[2], splitline[3], isLock ? "1" : "0", lockedTime.ToString());
                        }
                        else
                        {
                            streamWrite.WriteLine("{0},{1},{2},{3},{4}", splitline[0], splitline[1], splitline[2], isLock ? "1" : "0", lockedTime.ToString());
                        }
                    }
                    else
                    {
                        if (String.Compare(splitline[0], "Personal") == 0)
                        {
                            streamWrite.WriteLine("{0},{1},{2},{3},{4},{5}", splitline[0], splitline[1], splitline[2], splitline[3], splitline[4], splitline[5]);
                        }
                        else
                        {
                            streamWrite.WriteLine("{0},{1},{2},{3},{4}", splitline[0], splitline[1], splitline[2], splitline[3], splitline[4]);
                        }
                    }
                }
                streamWrite.Flush();
                streamWrite.Close();
                fileStream.Close();
             #pragma warning disable CS0168
            }
            catch (Exception exception)
            {
                #pragma warning restore CS0168
                if (streamReader != null)
                {
                    streamReader.Close();
                }
                if (streamWrite != null)
                {
                    streamWrite.Close();
                }
                if (fileStream != null)
                {
                    fileStream.Close();
                }
                string errorCode = "";
                try
                {
                    FileOperations.ReadToPersolanized();
                }
                catch (Exception exceptions)
                {
                    errorCode = exceptions.Message;
                    MessageBox.Show(errorCode + "Wrong Logins were forgotten", "Problem", MessageBoxButtons.OK);
                }
            }
        }
Пример #2
0
        static internal void ReadToPersolanized()
        {
            FileStream   fileStream   = new FileStream(@"c:\\final\\personalized.txt", FileMode.Open, FileAccess.Read);
            StreamReader streamReader = new StreamReader(fileStream);
            string       line         = streamReader.ReadLine();

            if (line == null)
            {
                streamReader.Close();
                fileStream.Close();
                new Error("Personalized File Destoryed.");
            }
            try
            {
                while (line != null)
                {
                    string[] lines = line.Split(',');
                    if (String.Compare(lines[0], "Personal") == 0)
                    {
                        AccountHolders.AllClients.Add(
                            new PersonalClient
                        {
                            accountNumber = lines[1],
                            Name          = lines[2],
                            Surname       = lines[3],
                            IsLock        = !(String.Compare(lines[4], "0") == 0),
                            LockedTime    = Convert.ToDateTime(lines[5])
                        });
                    }
                    else
                    {
                        AccountHolders.AllClients.Add(
                            new CompanyClient
                        {
                            accountNumber = lines[1],
                            CompanyName   = lines[2],
                            IsLock        = !(String.Compare(lines[3], "0") == 0),
                            LockedTime    = Convert.ToDateTime(lines[4])
                        });
                    }

                    line = streamReader.ReadLine();
                }
                streamReader.Close();
                fileStream.Close();
            }
#pragma warning disable CS0168
            catch (Exception exception)
            {
#pragma warning restore CS0168
                streamReader.Close();
                fileStream.Close();
                FileOperations.CreatePersonalizedFile("force");
                AccountHolders.AllClients.Clear();
                try
                {
                    (new PersonalClient()).Read();
                }
#pragma warning disable CS0168
                catch (Exception exceptions)
                {
#pragma warning restore CS0168
                }
                throw new Error("Personalized File Destoried,But Recoveried Old File!");
            }
        }
Пример #3
0
        public bool Check(string key)//double check
        {
            bool correct = false;

            if (String.Compare(FileOperations.PasswordToHash(key), this.password) != 0)
            {
                return(false);
            }
            FileStream   fileStream   = null;
            StreamReader streamReader = null;

            try
            {
                if (!File.Exists(@"c:\\final\\auth.txt"))
                {
                    new Error("File not found!");
                }
                fileStream   = new FileStream(@"c:\\final\\auth.txt", FileMode.Open, FileAccess.Read);
                streamReader = new StreamReader(fileStream);
                string line = streamReader.ReadLine();
                if (line == null)
                {
                    streamReader.Close();
                    fileStream.Close();
                    new Error("Auth File is Empty.");
                }
                while (line != null)
                {
                    string[] lines = line.Split(',');
                    if (lines[1].Length != 128)
                    {
                        throw new Error("");
                    }
                    if (String.Compare(lines[0], this.accountNumber) == 0)
                    {
                        if (String.Compare(lines[1], this.password) == 0)
                        {
                            correct = true;
                            break;
                        }
                    }
                    line = streamReader.ReadLine();
                }
                streamReader.Close();
                fileStream.Close();
            }
            #pragma warning disable CS0168
            catch (Exception exception)
            {
                #pragma warning restore CS0168
                streamReader.Close();
                fileStream.Close();
                string errorCode = "";
                try
                {
                    FileOperations.ReadToAuth();
                }catch (Exception exceptions)
                {
                    errorCode = exceptions.Message;
                }
                MessageBox.Show(errorCode + " Please Try Later!", "Problem", MessageBoxButtons.OK);
                return(false);
            }
            return(correct);
        }