C# 防止密碼偵測(竊取/偷窺/透視)工具[spy++]的TextBox元件『myPassBox』(CS_Protect_the_Password_inside_a_TextBox)

C# 防止密碼偵測(竊取/偷窺/透視)工具[spy++]的TextBox元件『myPassBox』(CS_Protect_the_Password_inside_a_TextBox)

C# 防止密碼偵測(竊取/偷窺/透視)工具[spy++]的TextBox元件『myPassBox』(CS_Protect_the_Password_inside_a_TextBox)


資料來源:https://dotblogs.com.tw/ricochen/2009/12/16/12485

https://codingvision.net/security/c-protect-the-password-inside-a-textbox


微軟工具:C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\spyxx.exe

外部工具:xkvp_4.5.20090205_azo


實際運用截圖






GITHUB:https://github.com/jash-git/CS_Protect_the_Password_inside_a_TextBox

code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public class myPassBox : 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);
        }
    }
}

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *