public static bool IsUsernameValid(string username) { EntityContext context = new EntityContext(); var profile = context.Profiles .Where(p => p.Username.ToLower() == username.ToLower() ).SingleOrDefault(); return profile == null; }
public static Profile CreateProfile(string username, string password) { EntityContext context = new EntityContext(); string salt = CreatePasswordSalt(); string passwordHash = CreatePasswordHash(password, salt); Profile profile = new Profile() { Username = username, Password = passwordHash, PasswordSalt = salt }; context.Profiles.Add(profile); context.SaveChanges(); return profile; }
public static Profile GetProfile(string username, string password, bool isHashed = false) { EntityContext context = new EntityContext(); Profile profile = context.Profiles .Where(p => p.Username == username) .SingleOrDefault(); if (profile != null) { string passwordHash = isHashed ? password : CreatePasswordHash(password, profile.PasswordSalt); if (profile.Password != passwordHash) { profile = null; } } return profile; }