Beispiel #1
0
        private void BSave_Click(object sender, EventArgs e)
        {
            userData.Login    = TBLogin.Text;
            userData.Password = TBPassword.Text;
            userData.VIN      = TBVIN.Text;
            FPassword fPassword1 = new FPassword();
            FPassword fPassword2 = new FPassword();

            fPassword1.ShowDialog();
            fPassword2.ShowDialog();
            String Password1 = fPassword1.Password;
            String Password2 = fPassword2.Password;

            if (Password1 == Password2)
            {
                TextWriter loginData = new StreamWriter(globalDataPath + loginDataFileName, false);
                loginData.WriteLine("Login " + SciPhyLib.Crypt.Encrypt(userData.Login, Password1));
                loginData.WriteLine("Password " + SciPhyLib.Crypt.Encrypt(userData.Password, Password1));
                loginData.WriteLine("VIN " + SciPhyLib.Crypt.Encrypt(userData.VIN, Password1));
                loginData.Close();
                logger.WriteLogLine("save logindata");
            }
            else
            {
                MessageBox.Show("Password or PIN is not equal!");
                logger.WriteLogLine("Tried to save logindata: Password or PIN is not equal!");
            }
        }
Beispiel #2
0
        void ReadLoginData()
        {
            UserData userDataOld = userData;

            userData.Login    = "";
            userData.Password = "";
            userData.VIN      = "";
            if (System.IO.File.Exists(globalDataPath + loginDataFileName) == true)
            {
                String     loginLine    = "";
                String     passwordLine = "";
                String     vinLine      = "";
                TextReader textReader   = new StreamReader(globalDataPath + loginDataFileName);
                try
                {
                    loginLine    = textReader.ReadLine();
                    passwordLine = textReader.ReadLine();
                    vinLine      = textReader.ReadLine();
                }
                catch (Exception)
                {
                    logger.WriteLogLine(string.Format("Reading user data failed! Clear file {0} if occour again!", globalDataPath + loginDataFileName));
                }

                textReader.Close();
                String[] loginLineData    = loginLine.Split(new char[] { ' ' });
                String[] passwordLineData = passwordLine.Split(new char[] { ' ' });
                String[] vinLineData      = vinLine.Split(new char[] { ' ' });
                if ((loginLineData.Length == 2) && (passwordLineData.Length == 2) && (vinLineData.Length == 2))
                {
                    if ((loginLineData[0] == "Login") && (passwordLineData[0] == "Password") && (vinLineData[0] == "VIN"))
                    {
                        FPassword    fPassword    = new FPassword();
                        DialogResult dialogResult = fPassword.ShowDialog();
                        if (dialogResult == DialogResult.OK)
                        {
                            String password = fPassword.Password;
                            userData.Login    = SciPhyLib.Crypt.Decrypt(loginLineData[1], password);
                            userData.Password = SciPhyLib.Crypt.Decrypt(passwordLineData[1], password);
                            userData.VIN      = SciPhyLib.Crypt.Decrypt(vinLineData[1], password);
                        }
                    }
                    else
                    {
                        logger.WriteLogLine(string.Format("Reading user data failed! Keywords unexpected! Clear file {0} if occour again!", globalDataPath + loginDataFileName));
                    }
                }
                else
                {
                    logger.WriteLogLine(string.Format("Reading user data failed! Amount of data unexpected! Clear file {0} if occour again!", globalDataPath + loginDataFileName));
                }
            }
            TBLogin.Text    = userData.Login;
            TBPassword.Text = userData.Password;
            TBVIN.Text      = userData.VIN;
            if (userDataOld != userData)
            {
                // invalidate bearer when changing credentials
                bearer.expires_in = 0;
            }
        }