public IActionResult Register(UsersWrapper user)
        {
            Users        SubUser   = user.NewUser;
            CryptoEngine Encrypter = new CryptoEngine();

            if (ModelState.IsValid)
            {
                bool ExUser = dbContext.users.Any(t => t.Email == SubUser.Email);
                if (ExUser == true)
                {
                    ModelState.AddModelError("NewUser.Email", "email already exists");
                    return(View("Index"));
                }
                PasswordHasher <Users> Hasher = new PasswordHasher <Users>();
                SubUser.Password = Hasher.HashPassword(SubUser, SubUser.Password);
                SubUser.Email    = Encrypter.Encrypt(SubUser.Email);
                SubUser.UserName = Encrypter.Encrypt(SubUser.UserName);
                dbContext.users.Add(SubUser);
                dbContext.SaveChanges();
                Users CurUser = dbContext.users.Last();
                HttpContext.Session.SetInt32("userid", CurUser.UserId);
                return(RedirectToAction("Success"));
            }
            else
            {
                return(View("Index"));
            }
        }
示例#2
0
        public static void addUser(User user)
        {
            UsersWrapper usersList = readUsers();

            usersList.getUsers().Add(user);
            writeUsers(usersList);
        }
        public IActionResult Login(UsersWrapper user)
        {
            LoginUsers   SubUser   = user.LoginUser;
            CryptoEngine Encrypter = new CryptoEngine();

            if (ModelState.IsValid)
            {
                SubUser.Email = Encrypter.Encrypt(SubUser.Email);
                Users userInDb = dbContext.users.FirstOrDefault(u => u.Email == SubUser.Email);
                if (userInDb == null)
                {
                    ModelState.AddModelError("LoginUser.Email", "Invalid Email");
                    return(View("Index"));
                }
                var hasher = new PasswordHasher <LoginUsers>();
                var result = hasher.VerifyHashedPassword(SubUser, userInDb.Password, SubUser.Password);
                if (result == 0)
                {
                    ModelState.AddModelError("LoginUser.Password", "Password is wrong");
                    return(View("Index"));
                }
                HttpContext.Session.SetInt32("userid", userInDb.UserId);
                return(RedirectToAction("Success"));
                // SubUser.Email=Users.Encrypt(SubUser.Email);
                // List<Users> AllUsers=dbContext.users.ToList();
                // foreach(Users item in AllUsers){
                //     item.Email=Encrypter.Decrypt(item.Email);
                //     if(item.Email==user.LoginUser.Email){
                //         Users userInDb = dbContext.users.FirstOrDefault(u => u.UserId == item.UserId);
                //         HttpContext.Session.SetInt32("userid",userInDb.UserId);
                //         var hasher = new PasswordHasher<LoginUsers>();
                //         var result = hasher.VerifyHashedPassword(SubUser, userInDb.Password, SubUser.Password);
                //         if(result == 0){
                //             ModelState.AddModelError("LoginUser.Password", "Password is wrong");
                //             return View("Index");
                //         }
                //         return RedirectToAction("Success");
                //     }
                // }
                // ModelState.AddModelError("LoginUser.Email", "Invalid Email");
                // return View("Index");
                // return
                // if(userInDb == null)
                // {
                // }
            }
            else
            {
                return(View("Index"));
            }
        }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

            User u = new User();

            u.setPassword("pasword");
            u.setUsername("usrnm");
            UsersWrapper wrapper = new UsersWrapper();
            List <User>  users   = new List <User>();

            users.Add(u);
            wrapper.setUsers(users);
            XMLManager.writeUsers(wrapper);
        }
示例#5
0
 public AD()
 {
     this.ldapConn = new LdapConnection(new Settings(/* configure settings here*/));
     this.users    = new UsersWrapper(this.ldapConn);
 }
示例#6
0
 public static void writeUsers(UsersWrapper users)
 {
     Easy.save(users, Constants.USERS_FILE_NAME);
 }
示例#7
0
 public AD(Settings settings) : base(settings)
 {
     this.users = new UsersWrapper(this);
 }