Esempio n. 1
0
        public ActionResult Create(UserRegistor model)
        {
            if (ModelState.IsValid)
            {
                var userDAO = new UserDAO();

                if (userDAO.CheckUsername(model.Username))
                {
                    ModelState.AddModelError("", "Tên người dùng đã tồn tại!");
                }
                else
                {
                    var user = new User();
                    user.Username    = model.Username;
                    user.Password    = MD5Hash.GetMd5Hash(model.Password);
                    user.CreatedDate = DateTime.Now;
                    user.ActiveCode  = Guid.NewGuid();
                    user.Role        = model.Role;
                    user.Status      = model.Status;

                    var result = userDAO.Insert(user);
                    if (result > 1)
                    {
                        ViewBag.Success = "Đăng ký người dùng thành công!";
                        model           = new UserRegistor();
                    }
                    else
                    {
                        ViewBag.Error = "Đăng ký tài khoản thất bại!";
                    }
                }
            }
            return(View());
        }
Esempio n. 2
0
 private void OK_Click(object sender, RoutedEventArgs e)
 {
     if (CheckFields())
     {
         string Sol = MD5Hash.RandomString();
         if (SelectedId == 0)
         {
             db.Accounts.Add(new Account
             {
                 Login    = Login.Text,
                 Fullname = Fullname.Text,
                 Email    = Email.Text,
                 Sol      = Sol,
                 Password = MD5Hash.GetMd5Hash(Password.Password + Sol)
             });
         }
         else
         {
             Account account = db.Accounts.Where(e => e.Id == SelectedId).Single();
             account.Login    = Login.Text;
             account.Fullname = Fullname.Text;
             account.Email    = Email.Text;
             account.Sol      = Sol;
             account.Password = MD5Hash.GetMd5Hash(Password.Password + Sol);
         }
         db.SaveChanges();
         Exit();
     }
 }
Esempio n. 3
0
        public IActionResult Registration(CustomerCreateVm model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            if (_serviceCustomer.GetUser(model.Mail) == true)
            {
                ViewBag.check = 0;
                return(View());
            }
            else
            {
                string passHash;
                using (MD5 md5Hash = MD5.Create())
                {
                    passHash = MD5Hash.GetMd5Hash(md5Hash, model.Password);
                }

                SaveUserDto saveUserDto = new SaveUserDto()
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Mail      = model.Mail,
                    Password  = passHash
                };

                _serviceCustomer.Add(saveUserDto);
                ViewBag.check = 1;
                return(View());
            }
        }
Esempio n. 4
0
 public string HashPassword(string password)
 {
     using (MD5 md5Hash = MD5.Create())
     {
         return(MD5Hash.GetMd5Hash(md5Hash, password));
     }
 }
Esempio n. 5
0
        public ActionResult Index(string Username, string Password)
        {
            string hashPW = null;

            //if (Session[Username] != null)
            //    return RedirectToAction("Gallery", "Product", Session[Username]);

            if (Username == null)
            {
                return(View());
            }

            Customer customer = CustomerData.GetCustomerByUsername(Username);

            using (MD5 md5Hash = MD5.Create())
            {
                hashPW = MD5Hash.GetMd5Hash(md5Hash, Password);
            }

            if (customer.Password != hashPW)
            {
                TempData["error"] = "<script>alert('Login Failed! Try Again!');</script>";
                return(View());
            }

            string sessionId = SessionData.CreateSession(customer.CustomerId);

            Session[sessionId]       = Username;
            Session[Username]        = sessionId;
            ViewData["cartQuantity"] = 0;
            ViewData["customer"]     = customer;
            return(RedirectToAction("Gallery", "Product", new { sessionId }));
        }
        public IActionResult Login(string email, string password)
        {
            if (email == null || password == null)
            {
                ViewData["login_error"] = "Fill in User and Password";
                return(View());
            }
            Employee user = dbcontext.employees.Where(x => x.Email == email).FirstOrDefault();

            using (MD5 md5Hash = MD5.Create())
            {
                string hashPwd = MD5Hash.GetMd5Hash(md5Hash, password);
                if (user == null || user.Password != hashPwd)
                {
                    ViewData["login_error"] = "User not found/Password Incorrect";
                    return(View());
                }
            }
            ViewData["userId"] = user.Id;
            HttpContext.Session.SetString("userId", user.Id);
            HttpContext.Session.SetString("Department", user.DepartmentsId);
            if (user.Role == Role.DEPT_HEAD || user.Role == Role.DEPT_REP || user.Role == Role.EMPLOYEE)
            {
                /*return RedirectToAction("viewCatalogue", "Department");*/
                return(RedirectToAction("Home", "Department"));
            }
            if (user.Role == Role.STORE_CLERK)
            {
                return(RedirectToAction("ViewRequisitions", "Requisition"));
            }
            else
            {
                return(RedirectToAction("Home", "StationeryStore", new { userid = user.Id }));
            }
        }
Esempio n. 7
0
        public ActionResult Login(string UserName, string Password)
        {
            if (UserName == null)
            {
                return(View());
            }

            UserInfo user = UserData.GetUserPassword(UserName);

            //Check if MD5 hash of entered pwd matches that in system.
            using (MD5 md5Hash = MD5.Create())
            {
                string hashPwd = MD5Hash.GetMd5Hash(md5Hash, Password);

                if (user == null)
                {
                    return(View());
                }

                if (user.Password != hashPwd)
                {
                    return(View());
                }
            }

            string SessionId = ShoppingCart.Models.Session.CreateSession(UserName);

            return(RedirectToAction("ViewProducts", "Gallery", new { username = UserName, sessionid = SessionId }));
        }
Esempio n. 8
0
 private void SignUp_Click(object sender, RoutedEventArgs e)
 {
     if (IsChecked())
     {
         try
         {
             string Sol = MD5Hash.RandomString();
             db.Accounts.Add(new Account
             {
                 Login    = Login.Text,
                 Email    = Email.Text,
                 Fullname = Fullname.Text,
                 Sol      = Sol,
                 Password = MD5Hash.GetMd5Hash(Password.Password + Sol),
                 Created  = DateTime.Now
             });
             db.SaveChanges();
             Exit();
         }
         catch (InvalidOperationException)
         {
             MessageBox.Show("There's error in registring your account. Please try again!");
             CleanFields();
         }
     }
 }
Esempio n. 9
0
        public ActionResult Edit(UserRegistor model)
        {
            if (ModelState.IsValid)
            {
                var userDAO = new UserDAO();
                var user    = new User();
                user.Id       = model.ID;
                user.Username = model.Username;
                user.Password = model.Password;
                user.Role     = model.Role;
                user.Status   = model.Status;

                if (!String.IsNullOrEmpty(user.Password) && !String.IsNullOrEmpty(user.Username))
                {
                    user.Password = MD5Hash.GetMd5Hash(user.Password);
                }
                var result = userDAO.Update(user);
                if (result)
                {
                    ViewBag.Success = "Thay đổi thông tin người dùng thành công!";
                    model           = new UserRegistor();
                }
                else
                {
                    ViewBag.Error = "Thay đổi thông tin người dùng thất bại!";
                }
            }
            return(View());
        }
Esempio n. 10
0
        public IActionResult ResetPassword(int?id)
        {
            if (HttpContext.Session.GetInt32("LoginLevel") != 2)
            {
                ViewBag.checkLogin = 0;
                return(View("../Home/AddCart"));
            }
            if (id == null)
            {
                return(NotFound());
            }

            UserDto userDto = _service.GetUser(id.Value);

            if (userDto == null)
            {
                return(NotFound());
            }
            string passHash;

            using (MD5 md5Hash = MD5.Create())
            {
                passHash = MD5Hash.GetMd5Hash(md5Hash, "123456");
            }

            SaveUserDto saveUserDto = _mapper.Map <UserDto, SaveUserDto>(userDto);

            saveUserDto.Password = passHash;
            _service.Update(saveUserDto);
            return(View("Thanks"));
        }
Esempio n. 11
0
        private void button1_Click(object sender, EventArgs e)
        {
            string msg = "Segundo a Lei geral Proteção de Dados nosso applicativo faz tratamento de seus dados inseridos a continuacao," +
                         " por sua seguranca mas se voce desejase retirar pode contatar conosco. Clickando aceito, voce aceita o uso de dados" +
                         " pessoais em nosso aplicativo.";


            if (checkInputs())
            {
                DialogResult dialogResult = MessageBox.Show(msg, "message", MessageBoxButtons.OKCancel);
                if (dialogResult == DialogResult.Cancel)
                {
                    this.Hide();
                    Home home = new Home();
                    home.Show();
                }
                Enderecos newEndereco = new Enderecos(
                    textBox2.Text,
                    textBox3.Text,
                    textBox4.Text,
                    textBox5.Text
                    );
                enderecoDB = new EnderecoRepo();
                enderecoDB.newEndereco(newEndereco);
                newEndereco.Id = enderecoDB.getLastId();


                Usuarios newUser = new Usuarios();
                newUser.SetEmail(email.Text);
                newUser.SetNome(textBox1.Text);
                MD5 md5Hash = MD5.Create();
                newUser.SetSenha(MD5Hash.GetMd5Hash(md5Hash, pass.Text));

                usuarioDB = new UsuariosRepo();
                usuarioDB.newUsuario(newUser);
                newUser.SetId(usuarioDB.lastUsuario());

                clientesDB = new ClienteRepo();
                Clientes newCliente = new Clientes(
                    newEndereco.Id,
                    false,
                    false,
                    textBox6.Text,
                    newUser.GetId()
                    );
                newCliente.Telefone = textBox7.Text;
                clientesDB.newCliente(newCliente);
                newCliente.IdUsuario = clientesDB.lastCliente();

                Session.setCliente(newCliente);
                this.Hide();
                Home homeW = new Home();
                homeW.Show();
            }
            else
            {
                MessageBox.Show("Campos faltantes");
            }
        }
Esempio n. 12
0
        public ClientProfile()
        {
            CreateMap <ClientPhone, PhoneDto>();
            CreateMap <CreateClientDto, Client>()
            .ForMember(c => c.Password, opt => opt.MapFrom(src => MD5Hash.GetMd5Hash(src.Password)))
            .ForMember(c => c.Points, opt => opt.MapFrom(src => 0))
            .ForMember(c => c.ClientPhones, opt => opt.MapFrom((dto, obj, i, context) =>
            {
                var clientPhones = new List <ClientPhone>();
                dto.Phones.Distinct().ToList().ForEach(c =>
                {
                    clientPhones.Add(new ClientPhone()
                    {
                        Phone = c
                    });
                });
                return(clientPhones);
            }));

            CreateMap <Client, ClientDto>()
            .ForMember(c => c.Total, opt => opt.MapFrom(src => src.Receipts.Where(c => c.ClientPaymentId == null).Sum(c => c.Amount)))
            .ForMember(d => d.Country, opt => opt.MapFrom((client, clientDto, i, context) =>
            {
                return(context.Mapper.Map <CountryDto>(client.Country));
            }))
            .ForMember(d => d.Phones, opt => opt.MapFrom((client, clientDto, i, context) =>
            {
                return(context.Mapper.Map <PhoneDto[]>(client.ClientPhones));
            }));
            CreateMap <UpdateClientDto, Client>()
            .ForMember(c => c.Password, opt => opt.MapFrom((dto, obj, i, context) =>
            {
                if (String.IsNullOrEmpty(dto.Password))
                {
                    return(obj.Password);
                }
                return(MD5Hash.GetMd5Hash(dto.Password));
            }));
            CreateMap <CUpdateClientDto, Client>()
            .ForMember(c => c.Password, opt => opt.MapFrom(src => src.Password == null ? "" : MD5Hash.GetMd5Hash(src.Password)));

            CreateMap <Client, AuthClient>()
            .ForMember(d => d.Country, opt => opt.MapFrom((client, authclient, i, context) =>
            {
                return(context.Mapper.Map <Country>(client.Country));
            }))
            .ForMember(d => d.Phones, opt => opt.MapFrom((client, auth, i, context) =>
            {
                return(context.Mapper.Map <PhoneDto[]>(client.ClientPhones));
            }));

            CreateMap <EditRequest, EditRequestDto>()
            .ForMember(c => c.Client, opt => opt.MapFrom((obj, dto, i, context) =>
            {
                return(context.Mapper.Map <ClientDto>(obj.Client));
            }));
        }
Esempio n. 13
0
        //[Authorize(Roles = "AddUser")]
        public IActionResult AddUser([FromBody] AddUserDTO addUserDTO)
        {
            try
            {
                addUserDTO.Name = addUserDTO.Name.Trim();
                User simelarUserName = _userRepositroy.Get(c => c.Username == addUserDTO.Username).FirstOrDefault();
                if (simelarUserName != null)
                {
                    var message = Messages.Exist;
                    message.ActionName     = "Add User";
                    message.ControllerName = "User";
                    return(Conflict(message));
                }

                User user = _mapper.Map <User>(addUserDTO);
                user.Password = MD5Hash.GetMd5Hash(user.Password);

                //check  for groups Id
                var groupsId = _groupRepository.Get().Select(c => c.Id);
                if (addUserDTO.GroupIds != null && addUserDTO.GroupIds.Count > 0)
                {
                    if (addUserDTO.GroupIds.Except(groupsId).Any())
                    {
                        var message = Messages.NotFound;
                        message.ActionName     = "Add User";
                        message.ControllerName = "User";
                        message.Message        = "يوجد مجموعة على الاقل غير موجودة";
                        return(NotFound(message));
                    }
                }
                //end checking
                _abstractUnitOfWork.Add(user, UserName());
                if (addUserDTO.GroupIds != null && addUserDTO.GroupIds.Count > 0)
                {
                    foreach (var item in addUserDTO.GroupIds)
                    {
                        UserGroup userGroup = new UserGroup()
                        {
                            UserId  = user.Id,
                            GroupId = item,
                        };
                        _abstractUnitOfWork.Add(userGroup, UserName());
                    }
                }
                _abstractUnitOfWork.Commit();
                return(Ok(_mapper.Map <UserResponDTO>(user)));
            }
            catch (Exception ex)
            {
                return(BadRequest(Messages.AnonymousError));
            }
        }
Esempio n. 14
0
        public bool LoginAdmin(string username, string password)
        {
            string md5Password = MD5Hash.GetMd5Hash(password);
            var    result      = db.Users.Count(x => x.Username == username && x.Password == md5Password && x.Role == "ADMIN");

            if (result > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 15
0
 public DbSeeder(SurerContext dbcontext)
 {
     using (MD5 md5Hash = MD5.Create())
     {
         User user1 = new User();
         user1.Id            = Guid.NewGuid().ToString();
         user1.FirstName     = "nyein";
         user1.LastName      = "wai";
         user1.Email         = "*****@*****.**";
         user1.Password      = MD5Hash.GetMd5Hash(md5Hash, "123456");
         user1.ContactNumber = 811997330;
         dbcontext.Add(user1);
         dbcontext.SaveChanges();
     }
 }
        public ActionResult Login([FromBody] Employee value)
        {
            if (value.Email == null || value.Password == null)
            {
                Object response = new
                {
                    message = "Please input credentials",
                    code    = HttpStatusCode.NonAuthoritativeInformation
                };
                return(Content(JsonConvert.SerializeObject(response)));
            }
            else
            {
                /*                Employee empInfo = dbcontext.employees
                 *                              .Where(x => x.Email == value.Email)
                 *                              .FirstOrDefault();*/
                Employee empInfo = deptService.findEmployeeByEmail(value.Email);
                using (MD5 md5Hash = MD5.Create())
                {
                    string Hash_Password = MD5Hash.GetMd5Hash(md5Hash, value.Password);

                    if (empInfo == null || empInfo.Password != Hash_Password)
                    {
                        Object response = new
                        {
                            message = " Unauthorized",
                            code    = HttpStatusCode.Unauthorized
                        };
                        return(Content(JsonConvert.SerializeObject(response)));
                    }
                    else
                    {
                        Object response = new
                        {
                            id             = empInfo.Id,
                            name           = empInfo.Name,
                            email          = empInfo.Email,
                            departmentName = empInfo.Departments.DeptName,
                            role           = empInfo.Role.ToString(),
                            status         = empInfo.Status,
                            message        = "Successfully Login",
                            code           = HttpStatusCode.OK
                        };
                        return(Content(JsonConvert.SerializeObject(response)));
                    }
                }
            }
        }
Esempio n. 17
0
 private void OK_Click(object sender, RoutedEventArgs e)
 {
     if (CheckFields())
     {
         if (SelectedId == 0)
         {
             User user = new User
             {
                 NameUser     = NameUser.Text,
                 Password     = MD5Hash.GetMd5Hash(Password.Text),
                 Adres        = Adres.Text,
                 Birthday     = Birthday.SelectedDate,
                 Dolzh        = Dolzh.Text,
                 Priem        = Priem.SelectedDate,
                 NPrikazPriem = NPrikazPriem.Text,
                 Uvol         = Uvol.SelectedDate,
                 NPrikazUvol  = NPrikazUvol.Text
             };
             if (!Oklad.Text.Equals(""))
             {
                 user.Oklad = Convert.ToDecimal(Oklad.Text);
             }
             db.Users.Add(user);
             LogInsert();
         }
         else
         {
             User user = db.Users.Where(e => e.IdUser == SelectedId).Single();
             LogUpdate(user);
             user.NameUser = NameUser.Text;
             user.Password = MD5Hash.GetMd5Hash(Password.Text);
             user.Adres    = Adres.Text;
             user.Birthday = Birthday.SelectedDate;
             user.Dolzh    = Dolzh.Text;
             if (!Oklad.Text.Equals(""))
             {
                 user.Oklad = Convert.ToDecimal(Oklad.Text);
             }
             user.Priem        = Priem.SelectedDate;
             user.NPrikazPriem = NPrikazPriem.Text;
             user.Uvol         = Uvol.SelectedDate;
             user.NPrikazUvol  = NPrikazUvol.Text;
         }
         db.SaveChanges();
         Exit();
     }
 }
Esempio n. 18
0
        private void addingToDB()
        {
            MD5 md5Hash = MD5.Create();

            MD5Hash.GetMd5Hash(md5Hash, textBox4.Text);
            Card newCard = new Card(
                Session.GetClientes().IdUsuario,
                textBox1.Text,
                textBox2.Text,
                MD5Hash.GetMd5Hash(md5Hash, textBox4.Text)
                );

            cardDB.newCard(newCard);
            ClienteRepo clientDB = new ClienteRepo();

            clientDB.updateUseCard(Session.GetClientes().IdUsuario);
        }
Esempio n. 19
0
        /// <summary>
        /// Add or update the speicified document group to the database using the <see cref="DocumentGroupModel.Name"/> property to match if the document group exists in the database
        /// </summary>
        /// <param name="crawledDocumentGroup"></param>
        /// <returns></returns>
        public bool AddOrUpdateDocumentGroup(DocumentGroupModel crawledDocumentGroup)
        {
            ValidateDocumentNames(crawledDocumentGroup);

            foreach (var crawledDocument in crawledDocumentGroup.Documents)
            {
                crawledDocument.Md5        = MD5Hash.GetMd5Hash(crawledDocument.Raw);
                crawledDocument.Identifier = Guid.NewGuid().ToString();
                crawledDocument.Name       = crawledDocument.Name.ToLower();
            }

            var folderName  = crawledDocumentGroup.Name.ToLower();
            var zipFileName = folderName + ".zip";

            crawledDocumentGroup.Name = zipFileName;

            return(this.ProcessDocumentGroup(crawledDocumentGroup));
        }
Esempio n. 20
0
        private bool ValidarLogin()
        {
            bool bRet = true;

            if (passEtx.Text.Length == 0)
            {
                bRet = false;
            }
            var usuarios = Usuario.Select(new Entities.Usuario()
            {
                IdUsuario = usuariosSpn.SelectedItem.ToString()
            });

            if (usuarios[0].Contrasena.ToUpper() != MD5Hash.GetMd5Hash(passEtx.Text).ToUpper())
            {
                bRet = false;
            }
            return(bRet);
        }
Esempio n. 21
0
        internal Colaborador Entrar(Usuario usuario)
        {
            if (TestConnection())
            {
                var md5 = new MD5Hash();

                var funcionario = collection.Find(
                    func =>
                    usuario.Username == func.Username &&
                    md5.GetMd5Hash(usuario.Senha).Equals(func.Senha)
                    ).SingleOrDefault();

                return(funcionario);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 22
0
 private void Recover_Click(object sender, RoutedEventArgs e)
 {
     if (IsChecked())
     {
         try
         {
             string  Sol  = MD5Hash.RandomString();
             Account user = db.Accounts.Where(e => e.Email.Equals(Email.Text)).Single();
             user.Sol      = Sol;
             user.Password = MD5Hash.GetMd5Hash(Password.Password + Sol);
             db.SaveChanges();
             MessageBox.Show("Your password is successfully changed", "Email Error", MessageBoxButton.OK, MessageBoxImage.Information);
             Exit();
         }
         catch (InvalidOperationException)
         {
             MessageBox.Show("Your email is invaild. Please try again!", "Email Error", MessageBoxButton.OK, MessageBoxImage.Error);
             CleanFields();
         }
     }
 }
Esempio n. 23
0
        public IActionResult Login(string Name, string Password)
        {
            if (Name == null)
            {
                return(View());
            }
            var user = dbcontext.Users
                       .Where(x => x.Name == Name)
                       .FirstOrDefault();

            if (user == null)
            {
                ViewData["login_error"] = "The username cannot be found.";

                return(View());
            }

            using (MD5 md5Hash = MD5.Create())
            {
                string hashPwd = MD5Hash.GetMd5Hash(md5Hash, Password);


                if (user.Password != hashPwd)
                {
                    ViewData["login_error"] = "Password is wrong. Please try again.";
                    return(View());
                }
            }
            //From /cart/checkout/~without login
            string sessionid = HttpContext.Session.GetString("sessionid");

            if (sessionid != null)
            {
                return(RedirectToAction("TransferCart", "Cart", new { userId = user.Id, sessionId = sessionid }));
            }
            HttpContext.Session.SetString("uname", user.Name);
            HttpContext.Session.SetString("userid", user.Id);
            return(RedirectToAction("ViewProducts", "Product", new { name = Name, userid = user.Id }));
        }
Esempio n. 24
0
        public ActionResult RegisterUser([FromBody] User value)
        {
            User user = dbcontext.User.Where(x => x.Email == value.Email).FirstOrDefault();

            if (user != null)
            {
                Object response = new
                {
                    message = "Email Already Existed",
                    code    = HttpStatusCode.Conflict
                };
                return(Content(JsonConvert.SerializeObject(response)));
            }
            else
            {
                using (MD5 md5Hash = MD5.Create())
                {
                    User newUser = new User();
                    newUser.Id        = Guid.NewGuid().ToString();
                    newUser.FirstName = value.FirstName;
                    newUser.LastName  = value.LastName;
                    newUser.Email     = value.Email;
                    newUser.Password  = MD5Hash.GetMd5Hash(md5Hash, value.Password);
                    if (!value.ContactNumber.Equals(0))
                    {
                        newUser.ContactNumber = value.ContactNumber;
                    }
                    dbcontext.Add(newUser);
                    dbcontext.SaveChanges();
                }
                Object response = new
                {
                    message = "  Created ",
                    code    = HttpStatusCode.Created
                };
                return(Content(JsonConvert.SerializeObject(response)));
            }
        }
Esempio n. 25
0
        public ActionResult LoginUser([FromBody] LoginUserModel userModel)
        {
            User user = dbcontext.User.Where(x => x.Email == userModel.Email).FirstOrDefault();

            if (user == null)
            {
                Object response = new
                {
                    message = "User does not exit",
                    code    = HttpStatusCode.NoContent
                };
                return(Content(JsonConvert.SerializeObject(response)));
            }
            using (MD5 md5Hash = MD5.Create())
            {
                string password = MD5Hash.GetMd5Hash(md5Hash, userModel.Password);
                if (user.Password == password)
                {
                    string token    = jWTAuthenticationManager.Authenticate(user.FirstName);
                    Object response = new
                    {
                        token = token,
                        user  = user,
                        code  = HttpStatusCode.OK
                    };
                    return(Content(JsonConvert.SerializeObject(response)));
                }
                else
                {
                    Object response = new
                    {
                        message = "Password Incorrect",
                        code    = HttpStatusCode.NoContent
                    };
                    return(Content(JsonConvert.SerializeObject(response)));
                }
            }
        }
Esempio n. 26
0
        private void button1_Click(object sender, EventArgs e)
        {
            string password = pass.Text;
            MD5    md5Hash  = MD5.Create();

            //MessageBox.Show(MD5Hash.GetMd5Hash(md5Hash, password));
            if (loginDB.checkUser(username.Text, MD5Hash.GetMd5Hash(md5Hash, password)))
            {
                if (!loginDB.checkAdmin(username.Text))
                {
                    Clientes currentCLiente = loginDB.getCliente(username.Text);
                    Session.setCliente(currentCLiente);
                }

                nextStep();
            }
            else
            {
                username.Text = "";
                pass.Text     = "";
                MessageBox.Show("Not Valid user");
            }
        }
Esempio n. 27
0
        public ActionResult Login(LoginViewModel model)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            var         matKhau  = MD5Hash.GetMd5Hash(md5, model.Password);
            tb_taikhoan taiKhoan = db.tb_taikhoan.SingleOrDefault(x => x.EmailDangKy.Equals(model.Email) && x.MatKhau.Equals(matKhau));

            try
            {
                if (taiKhoan == null)
                {
                    ViewBag.MessageLogin = "******";
                    return(View());
                }
                else
                {
                    Session["taiKhoan"] = taiKhoan;
                    return(RedirectToAction("Index", "Home"));
                }
            }
            catch (Exception e) {
                Debug.WriteLine("Error: " + e.Message.ToString());
                return(View());
            }
        }
Esempio n. 28
0
 public UserDto GetUser(string mail, string pasword)
 {
     using (MD5 md5Hash = MD5.Create())
     {
         string hash  = MD5Hash.GetMd5Hash(md5Hash, pasword);
         var    query = from p in MContext.Users
                        where (string.Compare(p.Mail, mail) == 0) && (string.Compare(p.Password, hash) == 0)
                        select new
         {
             UserID        = p.ID,
             UserLastName  = p.LastName,
             UserFirstName = p.FirstName,
             UserMail      = p.Mail,
             UserLevel     = p.Level,
             UserStatus    = p.Status
         };
         if (!query.Any())
         {
             return(null);
         }
         else
         {
             var     item = query.First();
             UserDto user = new UserDto()
             {
                 ID        = item.UserID,
                 LastName  = item.UserLastName,
                 FirstName = item.UserFirstName,
                 Mail      = item.UserMail,
                 Level     = item.UserLevel,
                 Status    = item.UserStatus
             };
             return(user);
         }
     }
 }
Esempio n. 29
0
        public ActionResult DangKyTKCaNhan(string email, string password, string password1, string fullname, string sex, string birthday, string provincial, string address, string mobile, string phone, string idcard, string idcardday, string noicap, string Acept)
        {
            List <string> arrMess = new List <string>();

            ViewBag.email = email;
            if (string.IsNullOrEmpty(email))
            {
                arrMess.Add("Email là bắt buộcc");
            }
            ViewBag.password = password;
            if (string.IsNullOrEmpty(password))
            {
                arrMess.Add("Mật khẩu là bắt buộc");
            }
            ViewBag.password1 = password1;
            if (string.IsNullOrEmpty(password1))
            {
                arrMess.Add("Nhập lại mật khẩu là bắt buộc");
            }
            if (!string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(password1) && !password.Equals(password1))
            {
                arrMess.Add("Mật khẩu không giống nhau");
                ViewBag.password  = "";
                ViewBag.password1 = "";
            }
            ViewBag.fullname = fullname;
            if (string.IsNullOrEmpty(fullname))
            {
                arrMess.Add("Tên người dùng là bắt buộc");
            }
            if (!string.IsNullOrEmpty(fullname) && fullname.Split(' ').Length < 2)
            {
                arrMess.Add("Mời nhập họ tên đầy đủ");
            }
            ViewBag.sex = sex;
            if (string.IsNullOrEmpty(sex))
            {
                arrMess.Add("Giới tính là bắt buộc");
            }
            ViewBag.provincial = provincial;
            if (string.IsNullOrEmpty(provincial))
            {
                arrMess.Add("Nơi sinh là bắt buộc");
            }
            ViewBag.address = address;
            if (string.IsNullOrEmpty(address))
            {
                arrMess.Add("Địa chỉ thường trú là bắt buộc");
            }
            ViewBag.mobile = mobile;
            if (string.IsNullOrEmpty(mobile))
            {
                arrMess.Add("Điện thoại di động là bắt buộc");
            }
            ViewBag.idcard = idcard;
            if (string.IsNullOrEmpty(idcard))
            {
                arrMess.Add("Số chứng minh là bắt buộc");
            }
            ViewBag.idcardday = idcardday;
            if (string.IsNullOrEmpty(idcardday))
            {
                arrMess.Add("Ngày cấp là bắt buộc");
            }
            ViewBag.noicap = noicap;
            if (string.IsNullOrEmpty(noicap))
            {
                arrMess.Add("Nơi cấp là bắt buộc");
            }

            if (string.IsNullOrEmpty(Acept))
            {
                arrMess.Add("đồng ý với quy định về đăng ký và sử dụng dịch vụ tại trang web này");
            }
            if (arrMess.Count > 0)
            {
                ViewBag.Message = arrMess;
                return(View());
            }
            using (var db = new db_thongtinthuyenvienEntities())
            {
                using (var context = db.Database.BeginTransaction())
                {
                    try
                    {
                        var arrTen = fullname.Split(' ');
                        var ten    = arrTen[arrTen.Length - 1];
                        var hoten  = "";
                        for (int i = 0; i < arrTen.Length - 1; i++)
                        {
                            hoten += arrTen[i] + " ";
                        }
                        tb_thuyenvien tv = new tb_thuyenvien()
                        {
                            HoTenLot        = hoten,
                            Ten             = ten,
                            GioiTinh        = sex,
                            NgaySinh        = birthday,
                            NoiSinh         = provincial,
                            DiaChiThuongTru = address,
                            Mobile          = mobile,
                            SoDienThoai     = phone,
                            SoCMND          = idcard,
                            NgayCap         = idcardday,
                            NoiCap          = noicap
                        };

                        db.tb_thuyenvien.Add(tv);
                        System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
                        tb_taikhoan tk = new tb_taikhoan()
                        {
                            SDTDangKy    = mobile,
                            EmailDangKy  = email,
                            MatKhau      = MD5Hash.GetMd5Hash(md5, password),
                            TenDangNhap  = email,
                            TrangThai    = false,
                            TKThuyenVien = true
                        };
                        tk.tb_thuyenvien.Add(tv);
                        db.tb_taikhoan.Add(tk);
                        db.SaveChanges();
                        context.Commit();
                        return(RedirectToAction("MessageRegister"));
                    }
                    catch {
                        context.Rollback();
                        ViewBag.Message.Add("Email đã được đăng ký!");
                    }
                }
            }
            return(View());
        }
Esempio n. 30
0
        public DBSeeder(CartContext dbcontext)
        {
            using (MD5 md5Hash = MD5.Create())
            {
                User user1 = new User();
                user1.Id       = Guid.NewGuid().ToString();
                user1.Name     = "Marine";
                user1.LastName = "Lee";
                user1.Email    = "*****@*****.**";
                string hashPwd1 = MD5Hash.GetMd5Hash(md5Hash, "marine123");
                user1.Password = hashPwd1;
                dbcontext.Add(user1);

                User user2 = new User();
                user2.Id       = Guid.NewGuid().ToString();
                user2.Name     = "Anne";
                user2.LastName = "Lim";
                user2.Email    = "*****@*****.**";
                string hashPwd2 = MD5Hash.GetMd5Hash(md5Hash, "anne123");
                user2.Password = hashPwd2;
                dbcontext.Add(user2);

                User user3 = new User();
                user3.Id       = Guid.NewGuid().ToString();
                user3.Name     = "John";
                user3.LastName = "Tan";
                user3.Email    = "*****@*****.**";
                string hashPwd3 = MD5Hash.GetMd5Hash(md5Hash, "john123");
                user3.Password = hashPwd3;
                dbcontext.Add(user3);


                Product product1 = new Product();
                product1.Id          = Guid.NewGuid().ToString();
                product1.Name        = "Grapes";
                product1.Price       = 5.50;
                product1.Description = "These grapes are sweet and juicy and has a thin firm skin.";
                product1.Image       = "grape.jpg";
                dbcontext.Add(product1);

                Product product2 = new Product();
                product2.Id          = Guid.NewGuid().ToString();
                product2.Name        = "Apples";
                product2.Price       = 4.50;
                product2.Description = "Large variety apple.Beautiful red or pinkish red skin.";
                product2.Image       = "apple.jpg";
                dbcontext.Add(product2);

                Product product3 = new Product();
                product3.Id          = Guid.NewGuid().ToString();
                product3.Name        = "Orange";
                product3.Price       = 4.30;
                product3.Description = "These mandarins are sweet, juicy, seedless and easy to peel.";
                product3.Image       = "orange.jpg";
                dbcontext.Add(product3);

                Product product4 = new Product();
                product4.Id          = Guid.NewGuid().ToString();
                product4.Name        = "Strawberry";
                product4.Price       = 5.45;
                product4.Description = "The fruit is an excellent source of vitamins C and K as well as fibre.";
                product4.Image       = "strawberry.jpg";
                dbcontext.Add(product4);

                Product product5 = new Product();
                product5.Id          = Guid.NewGuid().ToString();
                product5.Name        = "Dragonfruit";
                product5.Price       = 5.50;
                product5.Description = "The dragonfruit is a 'magical' fruit that integrates fruits, flowers.";
                product5.Image       = "dragon.jpg";
                dbcontext.Add(product5);


                Product product6 = new Product();
                product6.Id          = Guid.NewGuid().ToString();
                product6.Name        = "Watermelon";
                product6.Price       = 3.50;
                product6.Description = "A limited edition,this watermelon has much less seeds than other varieties.";
                product6.Image       = "watermelon.jpg";
                dbcontext.Add(product6);
                dbcontext.SaveChanges();


                Review review11 = new Review();
                review11.Id         = Guid.NewGuid().ToString();
                review11.UserId     = user1.Id;
                review11.ProductId  = product1.Id;
                review11.ReviewText = "Amazing quality, reliable seller. Extremely fast delivery.";
                dbcontext.Add(review11);
                dbcontext.SaveChanges();


                Review review21 = new Review();
                review21.Id         = Guid.NewGuid().ToString();
                review21.UserId     = user2.Id;
                review21.ProductId  = product1.Id;
                review21.ReviewText = "Wonderful transaction. Fruits were of the highest quality.";
                dbcontext.Add(review21);
                dbcontext.SaveChanges();

                Review review31 = new Review();
                review31.Id         = Guid.NewGuid().ToString();
                review31.UserId     = user3.Id;
                review31.ProductId  = product1.Id;
                review31.ReviewText = "Good product. Would buy again. Thank you MVC Fruit Store.";
                dbcontext.Add(review31);
                dbcontext.SaveChanges();


                Review review12 = new Review();
                review12.Id         = Guid.NewGuid().ToString();
                review12.UserId     = user1.Id;
                review12.ProductId  = product2.Id;
                review12.ReviewText = "The apples were fresh and sweet.";
                dbcontext.Add(review12);
                dbcontext.SaveChanges();


                Review review22 = new Review();
                review22.Id         = Guid.NewGuid().ToString();
                review22.UserId     = user2.Id;
                review22.ProductId  = product2.Id;
                review22.ReviewText = "Great quality. The apples are fresh.";
                dbcontext.Add(review22);
                dbcontext.SaveChanges();

                Review review32 = new Review();
                review32.Id         = Guid.NewGuid().ToString();
                review32.UserId     = user3.Id;
                review32.ProductId  = product2.Id;
                review32.ReviewText = "Very fast delivery. Reliable seller. Will order again.";
                dbcontext.Add(review32);
                dbcontext.SaveChanges();

                Review review13 = new Review();
                review13.Id         = Guid.NewGuid().ToString();
                review13.UserId     = user1.Id;
                review13.ProductId  = product3.Id;
                review13.ReviewText = "Great quality and taste. I will only buy from this shop from now on.";
                dbcontext.Add(review13);
                dbcontext.SaveChanges();


                Review review23 = new Review();
                review23.Id         = Guid.NewGuid().ToString();
                review23.UserId     = user2.Id;
                review23.ProductId  = product3.Id;
                review23.ReviewText = "Wonderful transaction. Fruits were of the highest quality.";
                dbcontext.Add(review23);
                dbcontext.SaveChanges();

                Review review33 = new Review();
                review33.Id         = Guid.NewGuid().ToString();
                review33.UserId     = user3.Id;
                review33.ProductId  = product3.Id;
                review33.ReviewText = "Very fast delivery.Reliable seller. Will order again.";
                dbcontext.Add(review33);
                dbcontext.SaveChanges();
            }
        }