123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System;
- using System.Collections.Generic;
- using OpenMetaverse;
- using OpenSim.Services.Interfaces;
- using log4net;
- using Nini.Config;
- using System.Reflection;
- using OpenSim.Data;
- using OpenSim.Framework;
- using OpenSim.Framework.Console;
- namespace OpenSim.Services.AuthenticationService
- {
-
-
-
-
-
-
- public class PasswordAuthenticationService :
- AuthenticationServiceBase, IAuthenticationService
- {
- private static readonly ILog m_log =
- LogManager.GetLogger(
- MethodBase.GetCurrentMethod().DeclaringType);
-
- public PasswordAuthenticationService(IConfigSource config) :
- base(config)
- {
- }
- public string Authenticate(UUID principalID, string password, int lifetime)
- {
- AuthenticationData data = m_Database.Get(principalID);
- if (data == null)
- {
- m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} not found", principalID);
- return String.Empty;
- }
- else if (data.Data == null)
- {
- m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} data not found", principalID);
- return String.Empty;
- }
- else if (!data.Data.ContainsKey("passwordHash") || !data.Data.ContainsKey("passwordSalt"))
- {
- m_log.DebugFormat(
- "[AUTH SERVICE]: PrincipalID {0} data didn't contain either passwordHash or passwordSalt", principalID);
- return String.Empty;
- }
- else
- {
- 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());
- if (data.Data["passwordHash"].ToString() == hashed)
- {
- return GetToken(principalID, lifetime);
- }
- else
- {
- m_log.DebugFormat(
- "[AUTH SERVICE]: Salted hash {0} of given password did not match salted hash of {1} for PrincipalID {2}. Authentication failure.",
- hashed, data.Data["passwordHash"], principalID);
- return String.Empty;
- }
- }
- }
- }
- }
|