C# Protect the Password inside a TextBox ZZ
If the Text property is called, it will send an WM_GETTEXT
message, so it will surely be an internal (safe) call. But if that message is received and the Text
property wasn't called, then it might be risky to return the password, so we'll not process that message.
I wrote a "safer" TextBox
here, just to show you the idea, feel free to write your own or simply improve this one.


class ProtectedTextBox : TextBox
{
// the malicious message, that needs to be handled
private const int WM_GETTEXT = 0x000D; // 'true' if the messages are sent from our program (from Text property)
// 'false' if they're sent by anything else
bool allowAccess { get; set; } public override string Text // overriding Text property
{
get
{
allowAccess = true; // allow WM_GETTEXT (because it's an internal call)
return base.Text; //this sends the message above in order to retrieve the TextBox's value
}
set
{
base.Text = value;
}
} protected override void WndProc(ref Message m)
{
if (m.Msg == WM_GETTEXT) // if the message is WM_GETTEXT
{
if (allowAccess) // and it comes from the Text property
{
allowAccess = false; //we temporarily remove the access
base.WndProc(ref m); //and finally, process the message
}
}
else
base.WndProc(ref m);
}
}
C# Protect the Password inside a TextBox ZZ的更多相关文章
- c# word interop encrypt with password protect with password
public static void EncryptWithPassword(string unEncryptedWordPath, string password) { Word.Applicati ...
- 使用Htmlhelper,创建文本框TextBox
下面通过HtmlHelper帮助类,创建文本框. 首先新建一个实体类,做为下面的例子: using System; using System.Collections.Generic; using Sy ...
- Linux基本操作命令
Linux基本操作命令 首先介绍一个名词“控制台(console)”,它就是我们通常见到的使用字符操作界面的人机接口,例如dos.我们说控制台命令,就是指通过字符界面输入的可以操作系统的命令,例如do ...
- Aspose.Cells相应操作及下载
Aspose.Cells相应操作 1,上传 1.1 Workbook Workbook workBook = new Workbook(); 属性: 名称 值类型 说明 Colors Color[] ...
- ASP.NET MVC 视图(五)
ASP.NET MVC 视图(五) 前言 上篇讲解了视图中的分段概念.和分部视图的使用,本篇将会对Razor的基础语法简洁的说明一下,前面的很多篇幅中都有涉及到视图的调用,其中用了很多视图辅助器,也就 ...
- WPF入门:数据绑定
上一篇我们将XAML大概做了个了解 ,这篇将继续学习WPF数据绑定的相关内容 数据源与控件的Binding Binding作为数据传送UI的通道,通过INotityPropertyChanged接口的 ...
- net-force.nl/steganography writeup
做CTF题好长一段时间了,真的可以学到很多东西.这次,我们开启 net-force.nl 的 Steganography之旅,所谓的隐写术. level 801: Training - Can you ...
- 在C#中使用Spire.doc对word的操作总结
在C#中使用Spire.doc对word的操作总结 在最近的工程中我们要处理一些word文档.通过在网上的大量搜索,我发现大多数软件功能不是不完整就是有重复.极少数可以完全实现的word组件又要收费. ...
- 浅谈Excel开发:三 Excel 对象模型
前一篇文章介绍了Excel中的菜单系统,在创建完菜单和工具栏之后,就要着手进行功能的开发了.不论您采用何种方式来开发Excel应用程序,了解Excel对象模型尤其重要,这些对象是您与Excel进行交互 ...
随机推荐
- OC - 2.OC基础知识介绍
一.基础语法 1> OC语言和C语言 C语言是面向过程的语言,OC语言是面向对象的语言 OC语言继承了C语言,并增加了面向对象的思想 以下内容只介绍OC语言与C语言的不同之处 2> 关键字 ...
- ASP.NET跨页面传值技巧
1 使用QueryString变量 QueryString是一种非常简单的传值方式,他可以将传送的值显示在浏览器的地址栏中.如果是传递一个或多个安全性要求不高或是结构简单的数值时,可以使用 ...
- 例子: 自制Flask首页导航.
# -*- coding:utf-8 -*- ''' Created on 2015年10月19日 ''' from flask import Flask, render_template impor ...
- 【CF493E】【数学】Vasya and Polynomial
Vasya is studying in the last class of school and soon he will take exams. He decided to study polyn ...
- ISO 学习笔记 2015-03-15
Objective--C 一 关键字 @property 定义变量函数 @synthesize 实现变量函数 二 函数 alloc 分配内存 init 初始化 new 替代上面两个函数 分配内存,并且 ...
- docker中搭建gitlab
1, 下载镜像 docker pull sameersbn/gitlab:7.4.3 # 下载gitlab镜像 docker pull sameersbn/mysql:latest # 下载gitla ...
- php 常用五种模式
/* 设计模式之单例模式 $_instance 必须声明为静态的私有变量 构造函数必须声明为私有,防止外部程序 new 类从而失去单例模式的意义 getInstance() 方法必须设置为公有的,必须 ...
- javascript 写农场迭代
/** * 农场一头小母牛 * 每年生头小母牛 * 母牛五岁产母牛 * 二十年上多少牛 */ 划分程序,母牛只管自己的年龄能不能产牛仔,母牛是model同时也是工厂 农场只管养牛,收获新牛. 一年一个 ...
- sass中 混合宏 VS 继承 VS 占位符 各自的使用时机和特点
初学者都常常纠结于这个问题“什么时候用混合宏,什么时候用继承,什么时候使用占位符?”其实他们各有各的优点与缺点,先来看看他们使用效果: a) Sass 中的混合宏使用 举例代码见 2-24 行 编译出 ...
- c#反射机制判断同一个类的两个实例的值是否完全一样
; i < properties1.Length; i++) { string s = properties1[i].DeclaringTyp ...