Пример #1
0
        public ActionResult Register(UserEntity user)
        {
            MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();

            //create an array of bytes we will use to store the encrypted password
            Byte[] hashedBytes;
            //Create a UTF8Encoding object we will use to convert our password string to a byte array
            UTF8Encoding encoder = new UTF8Encoding();

            hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(user.Password));

            HttpPostedFileBase file = Request.Files["NewProfilePic"];

            byte[] img;
            if (file.FileName == "")
            {
                img = null;
            }
            else
            {
                img = SocialNetwork.Services.MediaService.ConvertToBytes(file);
            }



            using (Models.Entidades.SocialNetworkEntities db = new SocialNetworkEntities())
            {
                Models.Entidades.User usr = new User();
                usr.profilepic = img;
                usr.password   = hashedBytes;
                usr.name       = user.Name;
                usr.lastname   = user.Lastname;
                usr.username   = user.Username;
                usr.email      = user.Email;
                usr.birthdate  = user.Birthdate;

                db.Users.Add(usr);
                db.SaveChanges();
            }

            return(View());
        }
Пример #2
0
        /// <summary>
        /// method for adding new user
        /// </summary>
        private void SaveExecute()
        {
            try
            {
                using (SocialNetworkEntities context = new SocialNetworkEntities())
                {
                    tblUser newUser = new tblUser();

                    newUser.FirstName = user.FirstName;
                    newUser.LastName  = user.LastName;
                    newUser.BirthDate = user.BirthDate;

                    newUser.Username = user.Username;

                    if (PasswordValidation(user.UserPassword))
                    {
                        newUser.UserPassword = user.UserPassword;
                    }
                    else
                    {
                        MessageBox.Show("Wrong password. Password must have at least 8 characters.\n(1 upper char, 1 lower char, 1 number and 1 special char)\nPlease try again.");
                    }

                    newUser.UserID = user.UserID;

                    context.tblUsers.Add(newUser);
                    context.SaveChanges();

                    MessageBox.Show("The user created successfully.");
                }
                signUp.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Wrong inputs, please check your inputs or try again.");
            }
        }