Exemplo n.º 1
0
        public static void Register(string username, string passwordHash, string certificatePath)
        {
            string newUserDirectoryPath = Application.Current.Properties["root"].ToString() + "\\" + username;

            if (Directory.Exists(newUserDirectoryPath))
            {
                MessageBox.Show("Username taken");
                return;
            }
            else
            {
                Directory.CreateDirectory(newUserDirectoryPath);
                Directory.CreateDirectory(newUserDirectoryPath + "\\home");
            }
            if (!CertificateChecker.certificateValid(certificatePath))
            {
                MessageBox.Show("Your certificate is invalid!");
                return;
            }

            X509Certificate2 userCertificate = new X509Certificate2(certificatePath);


            FileStream fileStream = new FileStream(Application.Current.Properties["lookupTableLocation"].ToString(), FileMode.Open);

            fileStream.Seek(-3, SeekOrigin.End);

            StreamWriter fileWriter = new StreamWriter(fileStream);

            fileWriter.Write(username + "\t" + passwordHash + "\t" + userCertificate.Thumbprint + "\n" + "EOF");
            fileWriter.Flush();
            fileWriter.Close();

            return;
        }
Exemplo n.º 2
0
        private void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            if (usernameBox.Text.Length == 0)
            {
                MessageBox.Show("Username too short");
                return;
            }
            if (passwordBox.Password.Length == 0)
            {
                MessageBox.Show("Password too short");
                return;
            }
            if (passwordBox.Password == passwordBoxRepeat.Password)
            {
                if (CertificateChecker.certificateValid(certificateBox.Text))
                {
                    RegisterUser.Register(usernameBox.Text, Hash.getSHA512Hash(passwordBox.Password), certificateBox.Text);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Invalid certificate");
                }

                return;
            }
        }
Exemplo n.º 3
0
        public static bool tryLogIn(string username, string passwordHash, string certificateLocation)
        {
            bool found = false;

            try
            {
                using (StreamReader streamReader = new StreamReader(Application.Current.Properties["lookupTableLocation"].ToString()))
                {
                    string fileLine = streamReader.ReadLine();
                    while (!found && (fileLine != "EOF"))
                    {
                        string[] usernamePassComboArray = fileLine.Split('\t');
                        if (usernamePassComboArray.Length == 3)
                        {
                            //if username and password hash are validated
                            if (usernamePassComboArray[0] == username && usernamePassComboArray[1].ToLower() == passwordHash.ToLower())
                            {
                                X509Certificate2 userCertificate = new X509Certificate2(certificateLocation);
                                if (userCertificate.Thumbprint == usernamePassComboArray[2])
                                {
                                    /*if (!CertificateChecker.checkCertificateUserConection(certificateLocation, username))
                                     * {
                                     *  MessageBox.Show("Invalid certificate for given username");
                                     *  return found;
                                     * }*/
                                    if (!CertificateChecker.certificateValid(certificateLocation))
                                    {
                                        return(found);
                                    }
                                    //certificate is valid
                                    found = true;
                                    return(found);
                                }
                                else
                                {
                                    MessageBox.Show("Invalid certificate for given username");
                                    return(found);
                                }
                            }
                        }
                        fileLine = streamReader.ReadLine();
                    }
                }
            }
            catch (Exception) { }

            return(found);
        }