private bool Login(string username, string password)
        {
            User   user        = AjudanteParaBD.SelectUserWithUsername(username);
            string insertedRep = SHA256Code.GenerateFromText(SHA256Code.GenerateFromText(password) + user.salt);

            return(user.rep.Equals(insertedRep));
        }
        public static bool Login(string username, string password)
        {
            string op = string.Empty;

            User user = AjudanteParaBD.SelectUserWithUsername(username);

            Console.Clear();
            if (user == null)
            {
                Console.WriteLine("\nErro! O utilizador inserido nao existe.");

                return(false);
            }

            //calcula o rep da palavra passe introduzida
            string insertedRep = SHA256Code.GenerateFromText(SHA256Code.GenerateFromText(password) + user.salt);

            if (user.rep.Equals(insertedRep))
            {
                Console.WriteLine("\nLogin efetuado com sucesso!\n");
                userLog = username;
                return(true);
            }
            else
            {
                Console.WriteLine("\nDados invalidos! Tente novamente.\n");
                return(false);
            }
        }
Esempio n. 3
0
        public static void RegistoMenu()
        {
            string username = string.Empty;
            string password = string.Empty;
            string rep      = string.Empty;
            string salt     = string.Empty;

            User user = null;

            do
            {
                Console.WriteLine("+----------------------------------------------------------+");
                Console.WriteLine("|                       Registo                            |");
                Console.WriteLine("+----------------------------------------------------------+");
                Console.WriteLine("\nIntroduza os dados solicitados!");
                Console.Write("Username:"******"Password:"******"Erro! A password deve conter no minimo 4 caracteres.");
                    }
                } while (password.Length < 4);

                //Calcula o SALT
                salt = BitConverter.ToString(SHA256Code.GenerateSalt()).Replace("-", "");

                //calcula o REP
                rep = SHA256Code.GenerateFromText(SHA256Code.GenerateFromText(password) + salt);

                user = new User(username, rep, salt);
            } while (!DataBaseFunctions.Register(user));

            LoginMenu();
        }