From b2fe47ecb11d4e6c6b0f9bc124cd7a8d4703784d Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sun, 20 May 2007 23:34:29 +0000 Subject: * Minor tweaks with new userserver * Fixed password encoding to match MD5 standard properly. * Fixed exception caused on user first login (minor) * Fixed exception caused by incorrect username (minor) * Returns login error rather than grid error if username is incorrect --- OpenGridServices.GridServer/Main.cs | 2 +- OpenGridServices.UserServer/UserManager.cs | 31 ++++++++++++++++++------------ OpenSim.Framework/Util.cs | 11 +++++++++++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/OpenGridServices.GridServer/Main.cs b/OpenGridServices.GridServer/Main.cs index 97f15c9..cad5fae 100644 --- a/OpenGridServices.GridServer/Main.cs +++ b/OpenGridServices.GridServer/Main.cs @@ -49,7 +49,7 @@ namespace OpenGridServices.GridServer public class OpenGrid_Main : BaseServer, conscmd_callback { private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll"; - private string GridDll = "OpenGrid.Framework.Data.DB4o.dll"; + private string GridDll = "OpenGrid.Framework.Data.MySQL.dll"; public GridConfig Cfg; public static OpenGrid_Main thegrid; diff --git a/OpenGridServices.UserServer/UserManager.cs b/OpenGridServices.UserServer/UserManager.cs index b579732..a312445 100644 --- a/OpenGridServices.UserServer/UserManager.cs +++ b/OpenGridServices.UserServer/UserManager.cs @@ -114,7 +114,14 @@ namespace OpenGridServices.UserServer try { UserProfileData profile = plugin.Value.getUserByName(fname,lname); - profile.currentAgent = getUserAgent(profile.UUID); + try + { + profile.currentAgent = getUserAgent(profile.UUID); + } + catch (Exception e) + { + // Ignore + } return profile; } catch (Exception e) @@ -295,18 +302,13 @@ namespace OpenGridServices.UserServer /// Authenticated? public bool AuthenticateUser(ref UserProfileData profile, string password) { - password = password.Remove(0, 3); //remove $1$ + OpenSim.Framework.Console.MainConsole.Instance.WriteLine( + OpenSim.Framework.Console.LogPriority.LOW, + "Authenticating " + profile.username + " " + profile.surname); - MD5CryptoServiceProvider MD5summer = new MD5CryptoServiceProvider(); - - byte[] byteString = System.Text.Encoding.ASCII.GetBytes(password + ":" + profile.passwordSalt); + password = password.Remove(0, 3); //remove $1$ - byteString = MD5summer.ComputeHash(byteString); - System.Text.StringBuilder s = new System.Text.StringBuilder(); - foreach (byte b in byteString) - { - s.Append(b.ToString("x2").ToLower()); - } + string s = Util.Md5Hash(password + ":" + profile.passwordSalt); return profile.passwordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase); } @@ -360,7 +362,9 @@ namespace OpenGridServices.UserServer // Current location agent.regionID = new LLUUID(); // Fill in later - agent.currentRegion = ""; // Fill in later + agent.currentRegion = new LLUUID(); // Fill in later + + profile.currentAgent = agent; } /// @@ -399,6 +403,9 @@ namespace OpenGridServices.UserServer passwd = (string)requestData["passwd"]; TheUser = getUserProfile(firstname, lastname); + if (TheUser == null) + return CreateLoginErrorResponse(); + GoodLogin = AuthenticateUser(ref TheUser, passwd); } else diff --git a/OpenSim.Framework/Util.cs b/OpenSim.Framework/Util.cs index 6f60925..400f415 100644 --- a/OpenSim.Framework/Util.cs +++ b/OpenSim.Framework/Util.cs @@ -1,4 +1,5 @@ using System; +using System.Security.Cryptography; using System.Collections.Generic; using System.Text; using libsecondlife; @@ -43,6 +44,16 @@ namespace OpenSim.Framework.Utilities return timestamp; } + public static string Md5Hash(string pass) + { + MD5 md5 = MD5CryptoServiceProvider.Create(); + byte[] dataMd5 = md5.ComputeHash(Encoding.Default.GetBytes(pass)); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < dataMd5.Length; i++) + sb.AppendFormat("{0:x2}", dataMd5[i]); + return sb.ToString(); + } + //public static int fast_distance2d(int x, int y) //{ // x = System.Math.Abs(x); -- cgit v1.1