/// <summary> /// 修改密码 /// </summary> /// <param name="id">用户id</param> /// <param name="oldP">旧密码</param> /// <param name="newP">新密码</param> /// <returns></returns> public bool ChangePassword(int id, string oldP, string newP) { if (string.IsNullOrWhiteSpace(oldP) || string.IsNullOrWhiteSpace(newP)) { return(false); } var r0 = _con.User.Where(e => e.Id.Equals(id)); if (!r0.Any()) { return(false); } var salt = r0.Select(s => s.Salt).FirstOrDefault(); var opd = Md5.GetMd5(oldP, salt); var r1 = r0.Where(e => e.PassWord.Equals(opd)); if (!r1.Any()) { return(false); } var salt1 = new RandomStringBuilder().Create(6); var r2 = r1.FirstOrDefault(); if (r2 != null) { r2.Salt = salt1; r2.PassWord = Md5.GetMd5(newP, salt1); r2.UpdateTime = DateTime.UtcNow; _con.User.Update(r2); } return(_con.SaveChanges() > 0); }
public static void Initialize(DanmuContext context, AppSettings appSettings) { context.Database.EnsureCreated(); //临时执行,修改以前的数据库 context.Database.ExecuteSqlRaw( "CREATE TABLE IF NOT EXISTS \"HttpClientCache\" (\"Id\" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1 ),\"Key\" TEXT COLLATE \"pg_catalog\".\"default\" NOT NULL, \"Value\" bytea, \"TimeStamp\" int8 NOT NULL,CONSTRAINT \"PK_HttpClientCache\" PRIMARY KEY ( \"Id\" ) );"); context.Database.ExecuteSqlRaw( "CREATE INDEX IF NOT EXISTS \"IX_HttpClientCache_Key\" ON \"HttpClientCache\" USING hash ( \"Key\" COLLATE \"pg_catalog\".\"default\" \"pg_catalog\".\"text_ops\" );"); context.Database.ExecuteSqlRaw("DO $$ BEGIN IF EXISTS(SELECT * FROM information_schema.columns WHERE table_name='User' and column_name='UpDateTime') THEN ALTER TABLE \"User\" RENAME COLUMN \"UpDateTime\" TO \"UpdateTime\"; END IF; END $$;"); if (!context.User.Any()) { var admin = appSettings.Admin; var salt = new RandomStringBuilder().Create(6); var user = new UserTable { Name = admin.User, Salt = salt, PassWord = Md5.GetMd5(Md5.GetMd5(admin.Password), salt), Role = UserRole.SuperAdmin }; context.User.AddAsync(user); context.SaveChanges(); } }
public static void Initialize(DanmuContext context, AppSettings appSettings) { context.Database.EnsureCreated(); if (context.User.Any()) { return; // DB has been seeded } var admin = appSettings.Admin; var salt = new RandomStringBuilder().Create(6); var user = new UserTable { Name = admin.User, Salt = salt, PassWord = Md5.GetMd5(Md5.GetMd5(admin.Password), salt), Role = UserRole.SuperAdmin }; context.User.AddAsync(user); context.SaveChanges(); }
public static void Initialize(DanmuContext context, AppSettings appSettings) { context.Database.EnsureCreated(); //临时执行,修改以前的数据库 context.Database.ExecuteSqlRaw("DO $$ BEGIN IF EXISTS(SELECT * FROM information_schema.columns WHERE table_name='User' and column_name='UpDateTime') THEN ALTER TABLE \"User\" RENAME COLUMN \"UpDateTime\" TO \"UpdateTime\"; END IF; END $$;"); if (!context.User.Any()) { var admin = appSettings.Admin; var salt = new RandomStringBuilder().Create(6); var user = new UserTable { Name = admin.User, Salt = salt, PassWord = Md5.GetMd5(Md5.GetMd5(admin.Password), salt), Role = UserRole.SuperAdmin }; context.User.AddAsync(user); context.SaveChanges(); } }