public object GetRecord(Entity entity, object key) { var table = new DynamicModel( AdminInitialise.ConnectionStringName, tableName: entity.TableName, primaryKeyField: entity.Key.ColumnName); var result = table.Single(key); return result; }
public IDictionary<string, object> GetRecord(Entity entity, params object[] key) { var table = new DynamicModel( Admin.ConnectionStringName, tableName: entity.TableName, primaryKeyField: entity.JoinedKey); var result = table.Single(key); return result; }
/// <summary> /// Verifies a password against the aspnet_Membership table. /// </summary> /// <param name="user"></param> /// <param name="password"></param> /// <returns></returns> /// <remarks> /// Thanks to Paul Brown for the article that helped me write this code: /// http://pretzelsteelersfan.blogspot.com/2012/11/migrating-legacy-apps-to-new.html /// And many thanks to Malcolm Swaine for the hashing code: /// http://www.codeproject.com/Articles/32600/Manually-validating-an-ASP-NET-user-account-with-a /// </remarks> private bool AspNetMembershipLogin(dynamic user, string password) { var db = new DynamicModel("NietoYostenDb", "aspnet_Membership", "Email"); var membership = db.Single((object)user.Email); if (!membership.IsApproved || membership.IsLockedOut) return false; // Compute aspnet hashed password byte[] bIn = Encoding.Unicode.GetBytes(password); byte[] bSalt = Convert.FromBase64String(membership.PasswordSalt); byte[] bAll = new byte[bSalt.Length + bIn.Length]; byte[] bRet = null; Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length); Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length); HashAlgorithm s = HashAlgorithm.Create("SHA1"); bRet = s.ComputeHash(bAll); string sha1HashedPassword = Convert.ToBase64String(bRet); // Check if password is correct if (sha1HashedPassword != membership.Password) return false; // Set password in this.users.HashedPassword (if password is correct) this.users.SetPassword(user.ID, password); return true; }