public string GetAccountInfo(string sMaInfo, string sConnInfo) { var eInfo = Cypher.Encrypt(sMaInfo); var mConnInfo = Cypher.Decrypt(sConnInfo); using (_repository) { var computerInfo = _repository.GetComputerInfo(eInfo); if (computerInfo == null) { return(CreateComputerInfo(eInfo, sConnInfo)); } GetDevice decCompInfo; if (IsUpdatedComputerInfo(mConnInfo, computerInfo, out decCompInfo) == false) { var response = UpdateComputerInfo(eInfo, mConnInfo, decCompInfo); if (string.IsNullOrWhiteSpace(response) == false) { return(response); } } return(IsValidDeviceInfo(decCompInfo)); } }
private bool IsUpdatedComputerInfo(string mConnInfo, string computerInfo, out GetDevice decCompInfo) { var connInfo = mConnInfo; decCompInfo = new JavaScriptSerializer().Deserialize <GetDevice>(Cypher.Decrypt(computerInfo)); return(connInfo == decCompInfo.Hk); }
private static void GetDevice(ConnectionFullModel client, JavaScriptSerializer jsSer) { var model = jsSer.Deserialize <GetDevice>(Cypher.Decrypt(client.Code)); IsValidDeviceInfo(model); client.DeviceName = model.Hn; client.StartDateTx = model.St.Date == DateTime.MinValue.Date ? "ND" : model.St.ToString(SharedConstants.DATE_FORMAT); client.EndDateTx = model.Et.Date == DateTime.MinValue.Date ? "ND" : model.Et.ToString(SharedConstants.DATE_FORMAT); client.IsValid = model.Iv; client.CodeId = model.Code; client.Code = AccountConstants.LstBadges[model.Code]; }
private bool IsUpdatedInfoServer(string mConnInfo, InfoServer infoServer, out GetDevice decCompInfo) { var connInfo = mConnInfo; decCompInfo = new JavaScriptSerializer().Deserialize <GetDevice>(Cypher.Decrypt(infoServer.Code)); if (connInfo == decCompInfo.Hk) { return(true); } return(false); }
public static string Decrypt(this string identifier, Algorithm algorithm, string key, EncodingType encType) { Cypher cypher = new Cypher(); cypher.EncryptionAlgorithm = algorithm; cypher.Encoding = encType; if (key != null) { cypher.Key = key; } return(cypher.Decrypt(identifier)); }
private void CreateInfoServer(string eInfo, string mConnInfo) { var model = new GetDevice { Hk = mConnInfo, //HostId Hn = Cypher.Decrypt(eInfo), //HostName St = DateTime.MinValue, Et = DateTime.MinValue, Iv = false, //Is valid license Code = AccountConstants.CODE_NEW }; _repository.AddInfoServer(Cypher.Encrypt(eInfo), Cypher.Encrypt(new JavaScriptSerializer().Serialize(model))); }
private string CreateComputerInfo(string eInfo, string sConnInfo) { var model = new GetDevice { Hk = Cypher.Decrypt(sConnInfo), //HostId Hn = Cypher.Decrypt(Cypher.Decrypt(eInfo)), //HostName St = DateTime.MinValue, Et = DateTime.MinValue, Iv = false, //Is valid license Code = AccountConstants.CODE_NEW }; _repository.AddComputerInfo(eInfo, Cypher.Encrypt(new JavaScriptSerializer().Serialize(model))); return(BuildResponse(SharedConstants.Client.STATUS_SCREEN_MESSAGE, AccountConstants.LstCodes[model.Code])); }
//private readonly IAccountService _serviceAccount; //public LoginSvc(IAccountService service) //{ // _serviceAccount = service; //} public ResponseMessage Login(LoginModel login) { try { using (var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()))) { var asyncUser = userManager.FindAsync(Cypher.Decrypt(login.Username), Cypher.Decrypt(login.Password)); asyncUser.Wait(); var result = asyncUser.Result; if (result == null) { return new ResponseMessage { IsSuccess = false, Message = ResAccount.ERROR_USERNAME_PASSWORD_INCORRECT } } ; using (var accountRepository = new AccountRepository()) { var userDetail = accountRepository.GetValidUser(result.Id); if (userDetail == null) { return(new ResponseMessage { IsSuccess = false, Message = ResAccount.ERROR_USERNAME_PASSWORD_INCORRECT }); } return(new ResponseMessage { IsSuccess = true, UserDetail = userDetail }); } } //Thread.Sleep(4000); //return _serviceAccount.Login(login); } catch (Exception ex) { return(new ResponseMessage { IsSuccess = false, Message = ex.Message }); } }
public UsuarioAdministracaoAgenda Authenticate(UsuarioAdministracaoAgenda info) { DataBase dataBase = new DataBase(); UsuarioAdministracaoAgenda usuario = null; StringBuilder sql = new StringBuilder(); sql.Append("select"); sql.Append(" uaa.UsuarioAdministracaoAgendaID"); sql.Append(", uaa.[Login]"); sql.Append(", uaa.Senha"); sql.Append(", uaa.Nome"); sql.Append(", uaa.Ativo"); sql.Append(" from"); sql.Append(" [dbo].[UsuarioAdministracaoAgenda] uaa"); sql.Append(" where"); sql.Append(String.Format(" uaa.[Login] = '{0}'", info.Login)); sql.Append(String.Format(" and uaa.Senha = '{0}'", info.Senha)); using (SqlConnection connection = dataBase.RetornaConexaoRastreabilidade()) { using (SqlCommand command = new SqlCommand(sql.ToString(), connection)) { connection.Open(); using (SqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { usuario = new UsuarioAdministracaoAgenda(); usuario.UsuarioAdministracaoAgendaID = Convert.ToInt32(dr["UsuarioAdministracaoAgendaID"]); usuario.Login = dr["Login"].ToString(); usuario.Senha = Cypher.Decrypt(dr["Senha"].ToString()); usuario.Nome = dr["Nome"].ToString(); usuario.Ativo = Convert.ToBoolean(dr["Ativo"]); } } } } return(usuario); }
public void OnPostAsync() { Output = string.Empty; if (InputFile != null) { var isParsed = FileService.ParseFile(InputFile, WebHostEnvironment.WebRootPath, out string parsingResult); if (!isParsed) { ErrorMessage = Constants.Errors.ParsingError; return; } Input = parsingResult; } if (string.IsNullOrEmpty(Input) || string.IsNullOrEmpty(Key)) { return; } try { Output = EncryptMode ? Cypher.Encrypt(Input, Key) : Cypher.Decrypt(Input, Key); } catch (Exception ex) { ErrorMessage = Constants.Errors.ProcessingError; Logger.LogError(ex.Message); } var isCreated = FileService.CreateFiles(Output, WebHostEnvironment.WebRootPath); if (!isCreated) { ErrorMessage = Constants.Errors.FilesCreationError; return; } }
private void CarregarParaEdicao(Int32 id) { try { UsuarioAdministracaoAgenda usuario = new UsuarioAdministracaoAgenda(); usuario = new UsuarioAdministracaoAgendaRepository() .Details(new UsuarioAdministracaoAgenda() { UsuarioAdministracaoAgendaID = id }); this.txtNome.Text = usuario.Nome; this.txtLogin.Text = usuario.Login; this.txtSenha.Text = Cypher.Decrypt(usuario.Senha); this.txtSenha.Attributes["type"] = "password"; } catch (Exception e) { Log.Create(e); Email.Send("Agendamento de congelação - falha na aplicação", e); this.msgDialog.Show("Erro", "Ocorreu uma falha ao carregar o registro para edição.", UserControl.Message.Type.Error); } }
public static T DeserializeAndDecrypt <T>(this string data) { return(new JavaScriptSerializer().Deserialize <T>(Cypher.Decrypt(data))); }
private void OnInfoAccountOk(IReactiveDeliveryClient reactiveDeliveryClient, IStale <ResponseMessageData <string> > obj, Action showWnd, IShellContainerVm vm) { if (obj.IsStale) { OnInfoAccountError(ResNetwork.ERROR_NETWORK_DOWN, showWnd); return; } if (obj.Data.IsSuccess == false) { OnInfoAccountError(obj.Data.Message, showWnd); return; } ConnectionInfoResponse response; try { response = new JavaScriptSerializer().Deserialize <ConnectionInfoResponse>(Cypher.Decrypt(obj.Data.Data)); } catch (Exception) { OnInfoAccountError("No fue posible obtener la respuesta del servidor. Revise que tenga la versión correcta en el cliente o en el servidor" , showWnd); return; } InitPosServices(reactiveDeliveryClient, showWnd, vm, response); }