示例#1
0
        public bool ValidPwd(string password, string username, string email)
        {
            MySqlConnection conn = Createconnection();

            MySqlCommand cmd = new MySqlCommand();

            conn.Open();

            SHA    hash = new SHA();
            string PWD  = hash.sha256encrypt(password, username, email);

            cmd.Connection  = conn;
            cmd.CommandText = "select * from Users where username = @username and Password = @pwd;";

            cmd.Parameters.AddWithValue("@username", username);
            cmd.Parameters.AddWithValue("@pwd", PWD);

            MySqlDataReader dataReader = cmd.ExecuteReader();

            if (dataReader.HasRows)
            {
                return(true);
            }

            return(false);
        }
示例#2
0
        public bool Register(string username, string password, string email)
        {
            MYSql sql = new MYSql();

            if (!sql.UserExists(username, email))
            {
                return(false);
            }
            SHA    Hash   = new SHA();
            string hashPw = Hash.sha256encrypt(password, username, email);

            MySqlConnection conn = sql.Createconnection();

            conn.Open();

            MySqlCommand cmd = new MySqlCommand();

            cmd.Connection = conn;

            cmd.CommandText = "insert into Users (guid,username,email,password) values (@guid, @user, @email, @pwd);";

            cmd.Parameters.AddWithValue("@guid", Guid.NewGuid().ToString());
            cmd.Parameters.AddWithValue("@user", username);
            cmd.Parameters.AddWithValue("@email", email);
            cmd.Parameters.AddWithValue("@pwd", hashPw);

            cmd.ExecuteNonQuery();

            return(true);
        }