From d167686adb2d4a08759cf7c23ced9d9edd209b77 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 2 Mar 2010 21:12:53 -0800 Subject: Better error handling on PasswordAuthenticationService --- .../PasswordAuthenticationService.cs | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs b/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs index 021dcf3..2fc9248 100644 --- a/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs +++ b/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs @@ -47,9 +47,9 @@ namespace OpenSim.Services.AuthenticationService public class PasswordAuthenticationService : AuthenticationServiceBase, IAuthenticationService { - //private static readonly ILog m_log = - // LogManager.GetLogger( - // MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); public PasswordAuthenticationService(IConfigSource config) : base(config) @@ -59,23 +59,27 @@ namespace OpenSim.Services.AuthenticationService public string Authenticate(UUID principalID, string password, int lifetime) { AuthenticationData data = m_Database.Get(principalID); - - if (!data.Data.ContainsKey("passwordHash") || - !data.Data.ContainsKey("passwordSalt")) + + if (data != null && data.Data != null) { - return String.Empty; - } + if (!data.Data.ContainsKey("passwordHash") || + !data.Data.ContainsKey("passwordSalt")) + { + return String.Empty; + } - string hashed = Util.Md5Hash(password + ":" + - data.Data["passwordSalt"].ToString()); + string hashed = Util.Md5Hash(password + ":" + + data.Data["passwordSalt"].ToString()); - //m_log.DebugFormat("[PASS AUTH]: got {0}; hashed = {1}; stored = {2}", password, hashed, data.Data["passwordHash"].ToString()); + //m_log.DebugFormat("[PASS AUTH]: got {0}; hashed = {1}; stored = {2}", password, hashed, data.Data["passwordHash"].ToString()); - if (data.Data["passwordHash"].ToString() == hashed) - { - return GetToken(principalID, lifetime); + if (data.Data["passwordHash"].ToString() == hashed) + { + return GetToken(principalID, lifetime); + } } + m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} or its data not found", principalID); return String.Empty; } } -- cgit v1.1