Esempio n. 1
0
        /// <summary>
        /// Retrieves an Account object by account_id
        /// </summary>
        /// <param name="id">String: The account_id to look up</param>
        /// <returns>Account: The full account details</returns>
        public static Account GetAccount(string id)
        {
            using (MySqlConnection mcon = new MySqlConnection(connString))
            using (MySqlCommand cmd = mcon.CreateCommand())
            {
                mcon.Open();
                cmd.CommandText = "SELECT account_id, account_nm, pass_hash, DATE_FORMAT(account_dob, '%d-%m-%Y') AS account_dob FROM accounts WHERE account_id = '" + id + "';";
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);

                List<string> list = new List<string>();
                using (MySqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        list.Add(reader.GetString("account_id"));
                        list.Add(reader.GetString("account_nm"));
                        list.Add(reader.GetString("pass_hash"));
                        list.Add(reader.GetString("account_dob"));
                    }
                }
                Account acc;
                try
                {
                    acc = new Account(list[0], list[1], list[2], list[3]);
                }
                catch
                {
                    throw new FormatException();
                }

                return acc;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Method to create an account in the database.
        /// </summary>
        /// <param name="acc">Account: The account to create.</param>
        public static void CreateAccount(Account acc)
        {
            // Salt and hash acc.Password
            Dictionary<string, string> hashAndSalt = Account.ComputeHash(acc.Password, null);

            // TODO: Parametise account name and email

            using (MySqlConnection mcon = new MySqlConnection(connString))
            using (MySqlCommand cmd = mcon.CreateCommand())
            {
                mcon.Open();
                cmd.CommandText = "INSERT INTO accounts (account_id, pass_hash, pass_salt, account_nm, account_dob) VALUES ('" + acc.Email + "', '" + hashAndSalt["hash"] + "', '" + hashAndSalt["salt"] + "', '" + acc.Name + "', '" + acc.Dob + "');";
                cmd.ExecuteNonQuery();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Verifies the user's input and if valid closes this form and starts an instance of Listener.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Start_Click(object sender, EventArgs e)
        {
            // Sort out dates
            string newDate = new_dobBox.Value.Year + "-" + new_dobBox.Value.Month + "-" + new_dobBox.Value.Day;

            // Create account object
            Account newAccount = new Account(newUsername, new_nameBox.Text, newPassword, newDate);

            // Get it into the database
            DbConnect.CreateAccount(newAccount);

            // Send a confirmation email message
            MailMessage mail = new MailMessage();
            SmtpClient smtp = new SmtpClient("mail.kajp.im");
            smtp.Port = 25;
            smtp.Credentials = new System.Net.NetworkCredential("donatello+kajp.im", "eijonu");
            smtp.EnableSsl = false;

            mail.From = new MailAddress("*****@*****.**");
            mail.To.Add(newUsername);
            mail.Subject = "Welcome to Donatello!";
            mail.Body = "Thanks for joining Donatello";

            try
            {
                //smtp.Send(mail);
            }
            catch (SmtpException)
            {
                // Oh well, not the end of the world if the email doesn't send.
            }

            Properties.Settings.Default.LastUsername = newUsername;
            Properties.Settings.Default.Save();
            DbConnect.SetClient(newUsername);
            Listener li = new Listener();
            li.ShowDialog();
            this.Hide();
        }