示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (tbSenha.Text.Equals(tbSenha2.Text))
            {
                Mongo mongo      = new Mongo();
                var   database   = mongo.getserver();
                var   collection = database.GetCollection <User>("user");

                var filter  = new BsonDocument("Cpf", user_.Cpf);
                var results = collection.Find(filter).ToList();
                if (results.Count == 0)
                {
                    throw new Exception();
                }

                User user = results.First();

                Cript cript = new Cript();
                user.Password = cript.ComputeSha256Hash(tbSenha.Text);

                var filter1 = Builders <User> .Filter.Eq(s => s.Id, user.Id);

                var result = collection.ReplaceOne(filter1, user);

                MessageBox.Show("Senha alterada com sucesso");
                this.Dispose();
            }
            else
            {
                MessageBox.Show("senhas não dão match ou não são validas");
            }
        }
示例#2
0
        public String cadastro(User user)
        {
            var collection = database.GetCollection <User>("user");

            if (user.Cpf == null || user.Cpf.Equals(""))
            {
                return("invalid_cpf");
            }
            if (user.Password == null || user.Password.Equals(""))
            {
                return("invalid_password");
            }
//            var result = validatePasswordStrenght(user.Password);
            if (user.Rg == null || user.Rg.Equals(""))
            {
                return("invalid_rg");
            }
            if (user.Name == null || user.Name.Equals(""))
            {
                return("invalid_name");
            }
            var filter  = new BsonDocument("Cpf", user.Cpf);
            var results = collection.Find(filter).ToList();

            if (results.Count > 0)
            {
                return("user_existent");
            }

            Cript cript = new Cript();


            user.Password   = cript.ComputeSha256Hash(user.Password);
            user.StartDate  = DateTime.Now.Date;
            user.UserStatus = UserStatus.NORMAL;
            user.Profile    = 2;

            collection.InsertOne(user);


            return("success");
        }
示例#3
0
        public User Login(string cpf, string senha)
        {
            Mongo mongo      = new Mongo();
            var   database   = mongo.getserver();
            var   collection = database.GetCollection <User>("user");

            var filter  = new BsonDocument("Cpf", cpf);
            var results = collection.Find(filter).ToList();

            if (results.Count == 0)
            {
                throw new Exception("Usuario inexistente ");
            }

            User user = results.First();

            Cript cript = new Cript();

            if (user.UserStatus == UserStatus.DELETED)
            {
                throw new Exception("Usuario inexistente ");
            }

            if (user.UserStatus == UserStatus.BLOQUED)
            {
                throw new Exception("Usuario Bloqueado");
            }

            if (!user.Password.Equals(cript.ComputeSha256Hash(senha)))
            {
                throw new WrongcredentialsException("Senha Invalida");
            }


            return(user);
        }