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进行交互 ...
随机推荐
- iOS 开发中的单例
在iOS开发中经常会用到单例,比如每个iOS程序本身就是一个单例,在比如进行个人偏好设置存储的时候用的也是一个单例.那我们如何自己来写一个单例类呢,用自己的单例对象呢?下面是我写的一个单例的头文件里的 ...
- 不同浏览器下css 透明度的写法
filter:alpha(opacity=90); /* IE transparent */ -moz-opacity:0.9; /* Moz + FF transparent */ opacity: ...
- spring mvc 错误
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin //跨域问题 respons ...
- Greedy is Good
作者:supernova 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=greedyAlg Joh ...
- php中浮点数计算问题
如果用php的+-*/计算浮点数的时候,可能会遇到一些计算结果错误的问题,比如echo intval( 0.58*100 );会打印57,而不是58,这个其实是计算机底层二进制无法精确表示浮点数的一个 ...
- PHP PhantomJs中文文档(翻译)
介绍 PHP PhantomJS 是一个灵活的 PHP 库加载页面通过 PhantomJS 无头浏览器并将返回页面响应.这是方便于需要JavaScript的支持,同时还支持截屏测试网站.功能列表通过 ...
- (转载)DBGridEh导出Excel等格式文件
DBGridEh导出Excel等格式文件 uses DBGridEhImpExp; {--------------------------------------------------------- ...
- FusionCharts xml入门教程
由于项目需求需要做一个报表,选择FusionCharts作为工具使用.由于以 前没有接触过报表,网上也没有比较详细的fusionCharts教程,所以决定好好研究FusionCharts,同时做一个比 ...
- Python学习笔记——正则表达式入门
# 本文对正则知识不做详细解释,仅作入门级的正则知识目录. 正则表达式的强大早有耳闻,大一时参加一次选拔考试,题目就是用做个HTML解析器,正则的优势表现得淋漓尽致.题外话不多讲,直接上干货: 1. ...
- 常用webservice接口地址
天气预报Web服务,数据来源于中国气象局Endpoint :http://www.webxml.com.cn/WebServices/WeatherWebService.asmxDisco ...