/// <summary> /// Confirms that user credentials are authentic /// </summary> /// <param name="userName">The username reserved for the user to login to GameSchool.</param> /// <param name="password">Password to confirm the user is allowed to log into given username.</param> /// <returns>A new user instance.</returns> public UserInfo Login(string userName, string password, string ipAddress) { if ((string.IsNullOrWhiteSpace(userName)) || (string.IsNullOrWhiteSpace(password))) { return null; } var userQuery = from x in GameSchoolEntities.UserInfoes where x.Username == userName select x; var userInfo = userQuery.FirstOrDefault(); //User not found, return null; if (userInfo == null) { return null; } // Compare user entered clear text password to hashed value in db if (!PasswordUtilities.VerifyHash(password, userInfo.Password)) { return null; // Password don't match, return null. } //Check if user status is active, If it's inactive we return null if (userInfo.StatusId != (int)UserStatus.Active) { return null; } var userLog = new UserLog { IpAddress = ipAddress, LoginTime = DateTime.Now, UserInfoId = userInfo.UserInfoId }; this.CreateUserLog(userLog); return userInfo; }
/// <summary> /// Creates user log /// </summary> /// <param name="userLog"></param> public void CreateUserLog(UserLog userLog) { if (userLog != null) { if (userLog.IpAddress != "::1") { GameSchoolEntities.UserLogs.AddObject(userLog); Save(); } } }