public bool Login(string userName, string password, out Guid key) { key = Guid.Empty; //TODO: Need to change this so that it sends back Invalid username or password if the credentials are invalid and some other message for errors try { Business.UserAccount userAccount = null; if (!Utility.Global.GetUserDataAccessor().ValidateUserCredentials(userName, password, out userAccount)) { return(false); } //If the user is already logged in, we need to disconnect the existing connection and remove him from the list of connected clients RemoveUser(userAccount.Id); //Get the call back for the client IAuthenticationServiceCallback callback = OperationContext.Current.GetCallbackChannel <IAuthenticationServiceCallback>(); //Create a CommunicationsStore to hold information about the connected client AuthenticationCommunicationsStore client = new AuthenticationCommunicationsStore(OperationContext.Current.InstanceContext, callback); client.UserAccount = userAccount; if (!OperationContext.Current.IncomingMessageProperties.ContainsKey(RemoteEndpointMessageProperty.Name)) { //This is for dev connections. client.IPAddress = "127.0.0.1"; } else { client.IPAddress = ((RemoteEndpointMessageProperty)OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name]).Address; } //TODO:May need to lock the list here for thread safety key = Guid.NewGuid(); AuthenticatedClients.Add(key, client); return(true); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(false); } }
public bool ValidateUserCredentials(string username, string password, out Business.UserAccount userAccount) { //TODO:Encrypt/Decrypt password using (Data.Entities entities = GetEntities()) { bool authenticated; authenticated = entities.Users.Where(u => u.UserName == username && u.Password == password).SingleOrDefault <LegendsOfKesmaiSurvival.Data.User>() != null; if (!authenticated) { userAccount = null; return(false); } else { userAccount = GetUserAccount(username); return(true); } } }