Exemple #1
0
        public void createUser(User user)
        {
            SecurityPassword encrPass = new SecurityPassword();
            string           password = encrPass.Encrypt(user.Password);

            try
            {
                SqlConnection connection = ManageDatabaseConnection("Open");
                using (SqlCommand sqlCommand = new SqlCommand("Insert_user1", connection))
                {
                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.Parameters.Add("@Username_Email", SqlDbType.VarChar).Value = user.Username;
                    sqlCommand.Parameters.Add("@IdNumber", SqlDbType.Int).Value           = user.IdNumber;
                    sqlCommand.Parameters.Add("@Name", SqlDbType.VarChar).Value           = user.Name;
                    sqlCommand.Parameters.Add("@MidName", SqlDbType.VarChar).Value        = user.SecondName;
                    sqlCommand.Parameters.Add("@Lastname", SqlDbType.VarChar).Value       = user.LastName;
                    sqlCommand.Parameters.Add("@SecondLastname", SqlDbType.VarChar).Value = user.SecondName;
                    sqlCommand.Parameters.Add("@Celular", SqlDbType.VarChar).Value        = user.Cellphone;
                    sqlCommand.Parameters.Add("@Password_Encr", SqlDbType.VarChar).Value  = password;
                    sqlCommand.Parameters.Add("@IdMajor", SqlDbType.Int).Value            = user.IdMajor;
                    sqlCommand.Parameters.Add("@IdUserType", SqlDbType.Int).Value         = user.Type;
                    sqlCommand.Parameters.Add("@HasCertificate", SqlDbType.Bit).Value     = "false";
                    sqlCommand.Parameters.Add("@IsSanctioned", SqlDbType.Bit).Value       = "false";


                    //connection.Open();
                    sqlCommand.ExecuteNonQuery();
                    connection = ManageDatabaseConnection("Close");
                }
            }
            catch (SqlException sqlException)
            {
                throw sqlException;
            }
        }
Exemple #2
0
 public bool comparesPasswordComingFromUser_toPasswordInDataBase(string username, string password)
 {
     bool isTheCorrectPassword = false;
     SecurityPassword securityPassword = new SecurityPassword();
     String encryptedPasswordFromDataBase = bringsEncryptedPasswordFromDataBase_underNameOfUser(username);
     String passwordFromUserAferEncryption = securityPassword.Encrypt(password);
     if (encryptedPasswordFromDataBase == passwordFromUserAferEncryption)
     {
         isTheCorrectPassword = true;
     }
     return isTheCorrectPassword;
 }
Exemple #3
0
        public override void Register()
        {
            new ValidationContract <Users>(this)
            .HasMaxLenght(x => x.Name, 50, "Nome deve conter até 50 char")
            .HasMinLenght(x => x.Name, 5, "Nome deve ter no minimo 5 char")
            .IsRequired(x => x.Name, "Nome do Usuario não foi informado")
            .IsEmail(x => x.Email, "Email invalido")
            .HasMaxLenght(x => x.Password, 32)
            .HasMinLenght(x => x.Password, 6)
            .IsRequired(x => x.Password, "Senha  do Usuario nao informada");

            Password = SecurityPassword.Encrypt(Password);
        }
Exemple #4
0
        public bool comparesPasswordComingFromUser_toPasswordInDataBase(string username, string password)
        {
            bool             isTheCorrectPassword           = false;
            SecurityPassword securityPassword               = new SecurityPassword();
            String           encryptedPasswordFromDataBase  = bringsEncryptedPasswordFromDataBase_underNameOfUser(username);
            String           passwordFromUserAferEncryption = securityPassword.Encrypt(password);

            if (encryptedPasswordFromDataBase == passwordFromUserAferEncryption)
            {
                isTheCorrectPassword = true;
            }
            return(isTheCorrectPassword);
        }
Exemple #5
0
        public void Update(string name, string email, string password)
        {
            Name     = Helpers.Capitalize(name);
            Email    = email.ToLower();
            Password = password;


            new ValidationContract <Users>(this)
            .HasMaxLenght(x => x.Name, 50, "Nome deve conter até 50 char")
            .HasMinLenght(x => x.Name, 5, "Nome deve ter no minimo 5 char")
            .IsRequired(x => x.Name, "Nome do Usuario não foi informado")
            .IsEmail(x => x.Email, "Email invalido")
            .HasMaxLenght(x => x.Password, 32)
            .HasMinLenght(x => x.Password, 6)
            .IsRequired(x => x.Password, "Senha  do Usuario nao informada");

            Password     = SecurityPassword.Encrypt(Password);
            DateofChange = DateTime.Now;
        }
Exemple #6
0
        public void createUser(User user)
        {
            SecurityPassword encrPass = new SecurityPassword();
            string password = encrPass.Encrypt(user.Password);
            try
            {
                SqlConnection connection = ManageDatabaseConnection("Open");
                using (SqlCommand sqlCommand = new SqlCommand("Insert_user1", connection))
                {

                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.Parameters.Add("@Username_Email", SqlDbType.VarChar).Value = user.Username;
                    sqlCommand.Parameters.Add("@IdNumber", SqlDbType.Int).Value = user.IdNumber;
                    sqlCommand.Parameters.Add("@Name", SqlDbType.VarChar).Value = user.Name;
                    sqlCommand.Parameters.Add("@MidName", SqlDbType.VarChar).Value = user.SecondName;
                    sqlCommand.Parameters.Add("@Lastname", SqlDbType.VarChar).Value = user.LastName;
                    sqlCommand.Parameters.Add("@SecondLastname", SqlDbType.VarChar).Value = user.SecondName;
                    sqlCommand.Parameters.Add("@Celular", SqlDbType.VarChar).Value = user.Cellphone;
                    sqlCommand.Parameters.Add("@Password_Encr", SqlDbType.VarChar).Value = password;
                    sqlCommand.Parameters.Add("@IdMajor", SqlDbType.Int).Value = user.IdMajor;
                    sqlCommand.Parameters.Add("@IdUserType", SqlDbType.Int).Value = user.Type;
                    sqlCommand.Parameters.Add("@HasCertificate", SqlDbType.Bit).Value = "false";
                    sqlCommand.Parameters.Add("@IsSanctioned", SqlDbType.Bit).Value = "false";

                    //connection.Open();
                    sqlCommand.ExecuteNonQuery();
                    connection = ManageDatabaseConnection("Close");
                }
            }
            catch (SqlException sqlException)
            {
                throw sqlException;
            }
        }
Exemple #7
0
 public Users GetUserOAuth(string email, string password) => _repository.Authenticate(email.ToLower(), SecurityPassword.Encrypt(password.Trim()));