Exemplo n.º 1
0
        public User GenerateUser()
        {
            string UserName = "";

            while (true)
            {
                UserName = RandomString(5);
                if (dbContext.Login.Where(l => l.UserName == UserName).Count() == 0)
                {
                    break;
                }
            }

            string Password = "******";
            string SaltKey  = EncryptHandler.RandomString(8);

            Models.DataModels.Login login = new Models.DataModels.Login()
            {
                UserName = UserName,
                Password = Password,
                Salt     = SaltKey
            };
            dbContext.SaveChanges();
            int loginID = dbContext.Login.Last().ID;

            //SQL.Insert("INSERT INTO `login` (`ID`, `username`, `password`, `salt`) VALUES (NULL, '" + UserName + "', '" + EncryptHandler.Encrypt(Password, SaltKey) + "', '" + SaltKey + "');");

            //string loginID = SQL.Select("SELECT `ID` FROM `login` WHERE `username` = '"+UserName+"'")[0];

            Models.DataModels.User user = new Models.DataModels.User()
            {
                Email     = "*****@*****.**",
                FirstName = "Voornaam",
                LastName  = "Achternaam",
                LoginID   = loginID,
                Type      = "user"
            };
            dbContext.User.Add(user);
            dbContext.SaveChanges();

            //SQL.Insert("INSERT INTO `user` (`ID`, `loginID`, `email`, `firstName`, `middleName`, `lastName`, `type`) VALUES (NULL, '"+loginID+"', '*****@*****.**', 'Voornaam', NULL, 'Achternaam', 'user');");

            return(new User()
            {
                UserName = UserName,
                Password = Password
            });
        }
Exemplo n.º 2
0
        public User GenerateUser()
        {
            string UserName = "";

            while (true)
            {
                UserName = RandomString(5);
                if (_dbContext.Login.Where(l => l.UserName == UserName).Count() == 0)
                {
                    break;
                }
            }

            string Password = "******";
            string SaltKey  = EncryptHandler.RandomString(8);
            string newPass  = EncryptHandler.Encrypt(Password, SaltKey);

            Models.DataModels.Login login = new Models.DataModels.Login()
            {
                UserName = UserName,
                Password = newPass,
                Salt     = SaltKey
            };
            _dbContext.Login.Add(login);
            _dbContext.SaveChanges();
            login = _dbContext.Login.OrderByDescending(u => u.ID).FirstOrDefault();

            Models.DataModels.User User = new Models.DataModels.User()
            {
                Email     = "*****@*****.**",
                FirstName = "Voornaam",
                LastName  = "Achternaam",
                LoginID   = login.ID,
                Type      = "user"
            };
            _dbContext.User.Add(User);
            _dbContext.SaveChanges();

            return(new User()
            {
                UserName = UserName,
                Password = Password
            });
        }