Exemplo n.º 1
0
        public void SignUp()
        {
            Console.Clear();
            Console.Out.Flush();
            while (true)
            {
                Console.WriteLine("\n> Vui lòng nhập đủ các thông tin phía dưới!");
                Console.WriteLine("Tên tài khoản: ");
                var username = Console.ReadLine().ToLower();
                Console.WriteLine("Tên chủ khoản: ");
                var name = Console.ReadLine().ToUpper();
                Console.WriteLine("Email: ");
                var email = Console.ReadLine().ToLower();
                Console.WriteLine("Mật khẩu: ");
                Utility ulti     = new Utility();
                var     password = ulti.EnterPassword();
                Console.WriteLine();
                Console.WriteLine("Nhập lại mật khẩu: ");
                var cfm_password = ulti.EnterPassword();
                Console.WriteLine();

                Console.WriteLine("Bạn muốn tạo tài khoản với thông tin vừa nhập? (y/n):");
                var _continue = Console.ReadLine().ToLower();
                if (_continue == "y")
                {
                    Console.Clear();
                    Console.Out.Flush();
                    if (ValidateRegister(username, name, email, password, cfm_password))
                    {
                        Model md = new Model();
                        if (md.CheckAccountExists(username))
                        {
                            Console.WriteLine("Tài khoản đã tồn tại! Hãy thử lại sau");
                        }
                        else if (md.CheckEmailExists(email))
                        {
                            Console.WriteLine("Email này đã tồn tại trong hệ thống! Vui lòng nhập email khác.");
                        }
                        else
                        {
                            // success
                            // Utility ulti = new Utility();
                            // var PwHashed = ulti.EncryptedString(password);
                            if (md.AccountRegister(new Account(username, name, email, password, 0)))
                            {
                                Console.WriteLine("Tài khoản đã được đăng ký thành công!");
                            }
                            else
                            {
                                Console.WriteLine("Đăng ký tài khoản thất bại! Hãy thử lại sau.");
                            }
                        }
                        break;
                    }
                }
            }

            Console.WriteLine("Ấn ENTER để tiếp tục...");
            Console.ReadLine();
        }
Exemplo n.º 2
0
        public Account SignIn()
        {
            Console.Clear();
            Console.Out.Flush();
            Console.WriteLine("\n> Vui lòng nhập đủ các thông tin phía dưới!");
            Console.WriteLine("Tên tài khoản: ");
            var username = Console.ReadLine().ToLower();

            Console.WriteLine("Mật khẩu: ");
            Utility ulti     = new Utility();
            var     password = ulti.EnterPassword();

            Console.WriteLine();

            // nếu thông tin đăng nhập đúng
            Model   md = new Model();
            Account rA = md.GetAccountByName(username);

            if (rA != null && ulti.EncryptedString(password, rA.Salt) == rA.Password)
            {
                Console.WriteLine("Đăng nhập thành công! Ấn ENTER để quay trở về...");
                Console.ReadLine();
                return(rA);
            }
            Console.WriteLine("Thông tin đăng nhập không chính xác! Ấn ENTER để quay trở về...");
            Console.ReadLine();
            return(null);
        }