예제 #1
0
 public User checkUsernamePassword()
 {
     DataLayer DataDal = new DataLayer();
     SaltDal   saltDal = new SaltDal();
     {
         List <Salt> saltValidate = (from u in saltDal.saltData
                                     where (u.userName == userName)
                                     select u).ToList <Salt>();
         if (saltValidate.Count != 1)
         {
             return(null);
         }
         string      userSalt      = saltValidate[0].salt;
         List <User> usersValidate = (from u in DataDal.users
                                      where (u.userName == userName)
                                      select u).ToList <User>();
         if (usersValidate.Count != 1)
         {
             return(null);
         }
         password = Convert.ToBase64String(PBKDF2(password, Convert.FromBase64String(userSalt), PBKDF2_ITT, HASH_SIZE));
         if (password == usersValidate[0].password)
         {
             FormsAuthentication.SetAuthCookie(usersValidate[0].type, true);
             return(usersValidate[0]);
         }
         return(null);
     }
 }
예제 #2
0
        private bool saveSalt(string salt, string purpose)  //purp: insert or update
        {
            SaltDal dal     = new SaltDal();
            Salt    saltObj = new Salt(userName, salt);

            if (purpose == "update")
            {
                dal.saltData.Attach(saltObj);
                dal.Entry(saltObj).Property(x => x.salt).IsModified = true;
            }
            else if (purpose == "signUp")
            {
                dal.saltData.Add(saltObj);
            }
            dal.SaveChanges();
            return(true);
        }