Exemplo n.º 1
0
 internal static Entities Data(string cnnStr)
 {
     var str = "metadata=res://*/Entities.csdl|res://*/Entities.ssdl|res://*/Entities.msl;provider=System.Data.SqlClient;provider connection string=\"" + ConfigurationManager.ConnectionStrings[cnnStr].ConnectionString + "\"";
     var db = new Entities(str);
     return db;
 }
        private bool CheckPassword(Entities db, string username, string password, bool updateLastLoginActivityDate, bool failIfNotApproved, out string salt, out int passwordFormat, out User usr)
        {
            var user = this.GetDBUser(db, username);

            usr = user;
            if (user == null)
            {
                salt = null;
                passwordFormat = -1;

                return false;
            }

            var enc = this.EncodePassword(password, user.PasswordFormat, user.PasswordSalt);
            passwordFormat = user.PasswordFormat;
            salt = user.PasswordSalt;
            if (enc == user.Password)
            {
                if (updateLastLoginActivityDate)
                {
                    if (this._UseSP)
                        db.Membership_SetUserLoginDate(user.UserID, DateTime.Now);
                    else
                    {
                        user.LastActivityDate = DateTime.Now;
                        user.LastLoginDate = DateTime.Now;

                        db.SaveChanges();
                    }
                }
                return true;
            }
            else
                return false;
        }
 public User GetDBUser(Entities db, string username)
 {
     if (this._UseSP)
         return db.Membership_GetUserByUsername(username, this.ApplicationName).FirstOrDefault();
     else
         return db.Users.FirstOrDefault(u => u.Username == username && u.Application.ApplicationID == this._AppID);
 }
 private bool CheckPassword(Entities db, string username, string password, bool updateLastLoginActivityDate, bool failIfNotApproved, out User usr)
 {
     string salt;
     int passwordFormat;
     return this.CheckPassword(db, username, password, updateLastLoginActivityDate, failIfNotApproved, out salt, out passwordFormat, out usr);
 }