/// <summary> /// Find user by activation code /// </summary> /// <param name="code"></param> private User FindUserByActivationCodeInternal(Entity parent, string code) { if (code != null && code != String.Empty) { var user = new User(Context); var sql = "spFindUser_byDomainActivationCode"; using (var cmd = Context.CreateStoredProcedureCommand(sql)) { cmd.Parameters.Add("@DomainGuid", SqlDbType.UniqueIdentifier).Value = parent.Guid; cmd.Parameters.Add("@ActivationCode", SqlDbType.NVarChar, 50).Value = code; using (var dr = cmd.ExecuteReader()) { dr.Read(); user.LoadFromDataReader(dr); dr.Close(); } } return user; } else { return null; } }
/// <summary> /// Find user by activation code /// </summary> /// <param name="code"></param> private User FindUserByActivationCodeInternal(Entity parent, string code) { if (code != null && code != String.Empty) { var user = new User(Context); var sql = "spFindUser_byDomainActivationCode"; using (var cmd = Context.CreateStoredProcedureCommand(sql)) { cmd.Parameters.Add("@DomainGuid", SqlDbType.UniqueIdentifier).Value = parent.Guid; cmd.Parameters.Add("@ActivationCode", SqlDbType.NVarChar, 50).Value = code; using (var dr = cmd.ExecuteReader()) { dr.Read(); user.LoadFromDataReader(dr); dr.Close(); } } return(user); } else { return(null); } }
/// <summary> /// Authenticate user /// </summary> /// <param name="userName"></param> /// <param name="password"></param> private User LoginUserInternal(Entity parent, string nameOrEmail, string password) { var user = new User(Context); // Load user from the database string sql = "spLoginUser"; using (var cmd = Context.CreateStoredProcedureCommand(sql)) { cmd.Parameters.Add("@ParentGuid", SqlDbType.UniqueIdentifier).Value = parent.Guid; cmd.Parameters.Add("@NameOrEmail", SqlDbType.NVarChar, 50).Value = nameOrEmail; using (var dr = cmd.ExecuteReader()) { if (!dr.Read()) { throw new EntityNotFoundException(ExceptionMessages.LoginFailed); } user.LoadFromDataReader(dr); } } // Compute password hash bool hashok = true; byte[] hash = User.ComputePasswordHash(password); // Compare the hash with the one in the database if (hash.Length != user.PasswordHash.Length) { hashok = false; } else { for (int i = 0; i < hash.Length; i++) { if (hash[i] != user.PasswordHash[i]) { hashok = false; break; } } } if (!hashok) { throw new SecurityException(ExceptionMessages.LoginFailed); } // Update context Context.UserGuid = user.Guid; Context.UserName = user.Name; Context.LogEvent(new Jhu.Graywulf.Logging.Event("Jhu.Graywulf.Registry.UserFactory.LoginUser", user.Guid)); return(user); }
private User FindUserByEmailInternal(Entity parent, string email) { var user = new User(Context); string sql = "spFindUser_byDomainEmail"; using (var cmd = Context.CreateStoredProcedureCommand(sql)) { cmd.Parameters.Add("@DomainGuid", SqlDbType.UniqueIdentifier).Value = parent.Guid; cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 128).Value = email; using (var dr = cmd.ExecuteReader()) { dr.Read(); user.LoadFromDataReader(dr); dr.Close(); } } return(user); }
public User FindUserByIdentity(Domain domain, string protocol, string authority, string identifier) { var user = new User(Context); var sql = "spFindUser_byIdentity"; using (var cmd = Context.CreateStoredProcedureCommand(sql)) { cmd.Parameters.Add("@DomainGuid", SqlDbType.UniqueIdentifier).Value = domain.Guid; cmd.Parameters.Add("@Protocol", SqlDbType.NVarChar, 25).Value = protocol; cmd.Parameters.Add("@Authority", SqlDbType.NVarChar, 250).Value = authority; cmd.Parameters.Add("@Identifier", SqlDbType.NVarChar, 250).Value = identifier; using (var dr = cmd.ExecuteReader()) { dr.Read(); user.LoadFromDataReader(dr); dr.Close(); } } return user; }
public User FindUserByIdentity(Domain domain, string protocol, string authority, string identifier) { var user = new User(Context); var sql = "spFindUser_byIdentity"; using (var cmd = Context.CreateStoredProcedureCommand(sql)) { cmd.Parameters.Add("@DomainGuid", SqlDbType.UniqueIdentifier).Value = domain.Guid; cmd.Parameters.Add("@Protocol", SqlDbType.NVarChar, 25).Value = protocol; cmd.Parameters.Add("@Authority", SqlDbType.NVarChar, 250).Value = authority; cmd.Parameters.Add("@Identifier", SqlDbType.NVarChar, 250).Value = identifier; using (var dr = cmd.ExecuteReader()) { dr.Read(); user.LoadFromDataReader(dr); dr.Close(); } } return(user); }
/// <summary> /// Authenticate user /// </summary> /// <param name="userName"></param> /// <param name="password"></param> private User LoginUserInternal(Entity parent, string nameOrEmail, string password) { var user = new User(Context); // Load user from the database string sql = "spLoginUser"; using (var cmd = Context.CreateStoredProcedureCommand(sql)) { cmd.Parameters.Add("@ParentGuid", SqlDbType.UniqueIdentifier).Value = parent.Guid; cmd.Parameters.Add("@NameOrEmail", SqlDbType.NVarChar, 50).Value = nameOrEmail; using (var dr = cmd.ExecuteReader()) { if (!dr.Read()) { throw new EntityNotFoundException(ExceptionMessages.LoginFailed); } user.LoadFromDataReader(dr); } } // Compute password hash bool hashok = true; byte[] hash = User.ComputePasswordHash(password); // Compare the hash with the one in the database if (hash.Length != user.PasswordHash.Length) { hashok = false; } else { for (int i = 0; i < hash.Length; i++) { if (hash[i] != user.PasswordHash[i]) { hashok = false; break; } } } if (!hashok) { throw new SecurityException(ExceptionMessages.LoginFailed); } // Update context Context.UserGuid = user.Guid; Context.UserName = user.Name; Context.LogEvent(new Jhu.Graywulf.Logging.Event("Jhu.Graywulf.Registry.UserFactory.LoginUser", user.Guid)); return user; }
private User FindUserByEmailInternal(Entity parent, string email) { var user = new User(Context); string sql = "spFindUser_byDomainEmail"; using (var cmd = Context.CreateStoredProcedureCommand(sql)) { cmd.Parameters.Add("@DomainGuid", SqlDbType.UniqueIdentifier).Value = parent.Guid; cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 128).Value = email; using (var dr = cmd.ExecuteReader()) { dr.Read(); user.LoadFromDataReader(dr); dr.Close(); } } return user; }