public static void CreateOrUpdate(UserInfo model) { if (model.Id < 0) { model.Password = SecurityFactory.GetSecurity().Encrypt(ConfigurationManager.AppSettings["DefaultPassword"].ToString()); if (SimpleOrmOperator.Create(model)) { WebTools.Alert("添加成功!"); } else { WebTools.Alert("添加失败!"); } } else { if (SimpleOrmOperator.Update(model)) { WebTools.Alert("修改成功!"); } else { WebTools.Alert("修改失败!"); } } }
public void SendToClient(Customer customer, MessageInfo info) { string xml = SerializeHelper.SerializeToXml(info); byte[] tmp = System.Text.Encoding.UTF8.GetBytes(SecurityFactory.GetSecurity().Encrypt(xml)); customer.Client.BeginSend(tmp, 0, tmp.Length, SocketFlags.None, new AsyncCallback(SendDataEnd), customer.Client); }
/// <summary> /// 创建时间 /// </summary> /// <param name="program">程序名称.</param> /// <param name="key">键值</param> /// <param name="cover">是否覆盖原键值</param> public static void CreateDateTime(string program, string key, bool cover) { RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software"); RegistryKey rkSub = rk.OpenSubKey(program, true); if (rkSub == null) { rk.CreateSubKey(program); rkSub = rk.OpenSubKey(program, true); // return false; } Object obj = rkSub.GetValue(key); if (cover) { rkSub.SetValue(key, SecurityFactory.GetSecurity().Encrypt(System.DateTime.Now.ToShortDateString())); } else if (obj == null) { rkSub.SetValue(key, SecurityFactory.GetSecurity().Encrypt(System.DateTime.Now.ToShortDateString())); } rkSub.Close(); rk.Close(); //return false; }
/// <summary> /// 写最后登陆的日期到隐藏目录下 /// </summary> /// <param name="program">程序名</param> public static void WriteLastLog(string program) { string path = System.Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\" + program + ".log"; CreateLastFile(program); StreamWriter streamWriter = null; try { streamWriter = new StreamWriter(path, false); streamWriter.WriteLine(SecurityFactory.GetSecurity().Encrypt(System.DateTime.Now.ToShortDateString())); streamWriter.Flush(); } catch (Exception ex) { log.Error(ex); } finally { if (streamWriter != null) { streamWriter.Close(); } } }
/// <summary> /// 获取时间 /// </summary> /// <param name="program">系统名称</param> /// <returns>如果存在就读取时间,否则就返回空字符串</returns> public static String GetDateTime(string program, string key) { RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software"); RegistryKey rkSub = rk.OpenSubKey(program); if (rkSub == null) { //rk.CreateSubKey(program); //rkSub = rk.OpenSubKey(program); //return System.DateTime.Now; return(string.Empty); } Object obj = rkSub.GetValue(key); if (obj != null) { rkSub.Close(); rk.Close(); return(SecurityFactory.GetSecurity().Decrypt(obj.ToString())); //rkSub.SetValue("regdate", System.DateTime.Now.ToShortDateString()); } rkSub.Close(); rk.Close(); return(string.Empty); }
/// <summary> /// 读取系统返回的时间 /// </summary> /// <param name="program">程序名</param> /// <returns>返回时间</returns> public static string ReadLastLog(string program) { string result = string.Empty; string path = System.Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\" + program + ".log"; CreateLastFile(program); StreamReader reader = null; System.IO.FileStream fs = new FileStream(path, FileMode.Open); try { reader = new StreamReader(fs); result = SecurityFactory.GetSecurity().Decrypt(reader.ReadLine()); } catch (Exception ex) { log.Error(ex); } finally { if (reader != null) { reader.Close(); } fs.Close(); } return(result); }
public static IContainer AutofacContainer() { var builder = new ContainerBuilder(); builder.RegisterType <Entities>().As(typeof(DbContext)).InstancePerLifetimeScope(); builder.RegisterType <UnitOfWork>().AsImplementedInterfaces().InstancePerLifetimeScope(); // 注册ApiController builder.RegisterApiControllers(Assembly.GetExecutingAssembly()) .Where(t => !t.IsAbstract && typeof(ApiController).IsAssignableFrom(t)); // BPL的注册放这里 builder.RegisterAssemblyTypes(Assembly.Load("DFHE.Survey.BLL")) .Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces().InstancePerLifetimeScope(); // DAL的注册放这里 builder.RegisterAssemblyTypes(Assembly.Load("DFHE.Survey.DAL")) .Where(t => t.Name.EndsWith("Repository")).AsImplementedInterfaces().InstancePerLifetimeScope(); IContainer container = builder.Build(); SecurityFactory.InitSecurityFactory(container.Resolve <IUserInfoRepository>()); return(container); }
/// <summary> /// 往TcpClient中写入一个MessageInfo对象 /// </summary> /// <param name="client">TcpClient对象</param> /// <param name="info">MessageInfo对象</param> public void WriteData(TcpClient client, MessageInfo info) { if (client != null && client.Connected) { string msg = SecurityFactory.GetSecurity().Encrypt(SerializeHelper.SerializeToXml(info)); byte[] myWriteBuffer = System.Text.Encoding.UTF8.GetBytes(msg); NetworkStream stream = client.GetStream(); bool flag = false; int i = 0; while (!flag) { if (i + 1024 <= myWriteBuffer.Length) { stream.Write(myWriteBuffer, i, 1024); } else { stream.Write(myWriteBuffer, i, myWriteBuffer.Length - i); flag = true; } stream.Flush(); i += 1024; } } //return string.Empty; }
public static string Login(string name, string pwd) { string sql = "select * from table_user_info where c_login_name='" + DALSecurityTool.TransferInsertField(name) + "' and c_pwd='" + DALSecurityTool.TransferInsertField(SecurityFactory.GetSecurity().Encrypt(pwd)) + "'"; ArrayList lists = FT.DAL.Orm.SimpleOrmOperator.QueryList(typeof(UserInfo), sql); if (lists.Count == 0) { return("2"); } else { UserInfo user = lists[0] as UserInfo; RoleInfo role = FT.DAL.Orm.SimpleOrmOperator.Query <RoleInfo>(user.RoleId); DepartmentInfo dept = FT.DAL.Orm.SimpleOrmOperator.Query <DepartmentInfo>(user.DepId); OperatorTick ot = new OperatorTick(user.Id, user.FullName, user.DepId, role.MenuStr, pwd); ot.Desp1 = user.WorkId; ot.Desp2 = dept.GlbmCode; ot.Desp3 = dept.DepCode; ot.Desp4 = dept.DepFullName; ot.Desp5 = user.FullName; ot.Desp6 = role.MenuStr; ot.Desp7 = role.RightStr; ot.Desp8 = user.Km.ToString(); return(FT.Web.OperatorTick.GenerateOpTicket(ot)); } //return "1"; }
private static void Encode(BinaryWriter wtr, TcpPacketRequestFileTransportExtend extend) { byte[] buf = BitConverter.GetBytes(extend.FileID); byte[] enBuf = SecurityFactory.Encrypt(buf, extend.EncryptKey); wtr.Write(enBuf.Length); wtr.Write(enBuf); }
public ResultVO Logout() { var result = new ResultVO { Result = 1 }; SecurityFactory.Logout(); return(result); }
private static TcpPacketRequestFileTransportExtend ResolveRequestFileTransportExtend(BinaryReader rdr, byte[] priKey) { TcpPacketRequestFileTransportExtend extend = new TcpPacketRequestFileTransportExtend(); int len = rdr.ReadInt32(); byte[] buf = rdr.ReadBytes(len); byte[] deBuf = SecurityFactory.Decrypt(buf, priKey); extend.FileID = BitConverter.ToInt64(deBuf, 0); return(extend); }
/// <summary> /// Create a new user account. /// </summary> /// <param name="appUserRegisterVm">Registration view model.</param> public async Task <StggResult <AppUserVm> > RegisterAsync(AppUserRegisterVm appUserRegisterVm) { // Make sure that the email isn't being used by an existing user. var stggResult = new StggResult <AppUserVm>(); var userByEmail = await AppUserManager.FindByEmailAsync(appUserRegisterVm.Email); if (userByEmail != null) { stggResult.AddError("The specified email address already exist within the system. Please enter a different email address."); return(stggResult); } // Create data models from the register view model. var userProfile = SecurityFactory.BuildOneUserProfile_ByAppUserRegisterVm( appUserRegisterVm, AppSettings.DefaultUserAvatar); var user = SecurityFactory.BuildOneUser_ByAppUserRegisterVm( appUserRegisterVm, userProfile); // Save changes to the database. var createResult = await AppUserManager.CreateAsync(user, appUserRegisterVm.Password); if (createResult.Succeeded == false) { stggResult.AddError("Failed to create user account."); return(stggResult); } // Add user to the User Role var addRoleResult = await AppUserManager.AddToRoleAsync(user.Id, Role.NAME_USER); if (addRoleResult.Succeeded == false) { stggResult.AddError("Failed to create user account."); return(stggResult); } // Get the application user instance. var stggResUser = (await FindByIdAsync(user.Id)).Value; stggResUser.EmailConfirmationToken = GenerateEmailConfirmationToken(stggResUser.Id); // Set the stgg output stggResult.SetValue(stggResUser); // Return the application user. return(stggResult); }
/// <summary> /// 登录 /// </summary> /// <param name="user"></param> /// <returns></returns> ///[HTTPBasicAuthorizeAttribute] public ResultVO Login(UserInfo user) { var res = _userInfoService.Login(user); if (SecurityFactory.CurrentUser == null || SecurityFactory.CurrentUser.UserName != user.UserName) { SecurityFactory.Login(new UserInfo { UserName = user.UserName }, null); } return(res); //return new ResultVO() { Result = 0, Data = SecurityFactory.CurrentUser }; }
protected override void OnStartup(StartupEventArgs e) { var encMachineName = ConfigurationManager.AppSettings["MachineName"]; var key = ConfigurationManager.AppSettings["SecurityKey"]; var machineName = SecurityFactory.Decrypt(encMachineName, key); var fileName = $@"{FolderFactory.SettingFolder}\{Environment.MachineName}.ini"; if (!File.Exists(fileName)) { MessageBox.Show("Photomanager kan niet worden geladen! Gelieve contact op te nemen met de administrator.", "Fout", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } if (string.IsNullOrEmpty(machineName) || !machineName.Equals(Environment.MachineName)) { MessageBox.Show($"Photomanager kan niet worden geladen! => machine: {Environment.MachineName}", "Fout", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } var currentProcess = Process.GetCurrentProcess(); if (!IsProcessRunning(currentProcess.ProcessName)) { PhotomanagerFactory.CloseBusyLogs(); ActivityLogFileName = $"Activity_{DateTime.Now:yyyyMMddHHmmss}_B"; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; if (IsAdHoc) { var adhocStatusFile = NetworkFactory.GetAdHocFileName(Variables.AdHocStatusFile, ActivityLogFileName); if (!NetworkFactory.IsCorrectSsid(adhocStatusFile, ConfigurationManager.AppSettings["AdHocSSID"])) { NetworkFactory.SetAdHocNetwork(ActivityLogFileName); } if (!NetworkFactory.IsStarted(adhocStatusFile)) { NetworkFactory.StartAdHocNetwork(adhocStatusFile, ActivityLogFileName); } } base.OnStartup(e); } else { if (Process.GetProcessesByName(currentProcess.ProcessName).Length > 1) { MessageBox.Show("De applicatie is reeds gestart!", "Informatie", MessageBoxButton.OK, MessageBoxImage.Information); Current.Shutdown(); } } }
private static UdpPacketImageExtend ResolveImageExtend(BinaryReader rdr, byte[] priKey) { UdpPacketImageExtend extend = new UdpPacketImageExtend(); int len = rdr.ReadInt32(); byte[] buf = rdr.ReadBytes(len); byte[] deBuf = SecurityFactory.Decrypt(buf, priKey); using (MemoryStream ms = new MemoryStream(deBuf)) { Image image = Image.FromStream(ms); extend.Image = image; } return(extend); }
private void btnModify_Click(object sender, EventArgs e) { if (this.txtOldPwd.Text.Trim() == string.Empty) { MessageBoxHelper.Show("����������룡"); return; } else if (SecurityFactory.GetSecurity().Encrypt(this.txtOldPwd.Text.Trim()) != UserManager.LoginUser.Password) { MessageBoxHelper.Show("������������"); return; } else if (this.txtNewPwd.Text.Trim() == string.Empty) { MessageBoxHelper.Show("�����������룡"); return; } else if (this.txtNewPwd.Text.Trim().Length < 6) { MessageBoxHelper.Show("�����������ڵ���6λ��"); this.txtRepeatPwd.Text = string.Empty; this.txtNewPwd.Text = string.Empty; this.txtNewPwd.Focus(); return; } else if (this.txtNewPwd.Text.Trim() != this.txtRepeatPwd.Text.Trim()) { MessageBoxHelper.Show("��������������벻һ�£�"); this.txtRepeatPwd.Text = string.Empty; this.txtNewPwd.Text = string.Empty; this.txtNewPwd.Focus(); return; } if (UserManager.ResetPwd(this.txtNewPwd.Text.Trim())) { MessageBoxHelper.Show("�ijɹ���"); this.txtNewPwd.Text = string.Empty; this.txtOldPwd.Text = string.Empty; this.txtRepeatPwd.Text = string.Empty; this.txtOldPwd.Focus(); } else { MessageBoxHelper.Show("��ʧ�ܣ�"); } }
/// <summary> /// 重新设置使用开始日期 /// </summary> /// <param name="program">程序名</param> /// <param name="regdate">日期</param> public static void ResetRegDate(string program, DateTime regdate) { RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software"); RegistryKey rkSub = rk.OpenSubKey(program, true); if (rkSub == null) { rk.CreateSubKey(program); rkSub = rk.OpenSubKey(program, true); // return false; } Object obj = rkSub.GetValue("regdate"); rkSub.SetValue("regdate", SecurityFactory.GetSecurity().Encrypt(regdate.ToShortDateString())); rkSub.Close(); rk.Close(); }