Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have error in my windows application form that "System.window.form.TextBox" does not contain any defination for "Securetext" accepting a first argument of type "System.window.form.TextBox" could be found (are you missing a using directive or an assebmly reffrence


C#
private byte[] GetPasswordBytes()
   {
       // The real password characters is stored in System.SecureString
       // Below code demonstrates on converting System.SecureString into Byte[]
       // Credit: http://social.msdn.microsoft.com/Forums/vstudio/en-US/f6710354-32e3-4486-b866-e102bb495f86/converting-a-securestring-object-to-byte-array-in-net

       byte[] ba = null;

       if (secureTextBox1.Text.Length == 0)
           ba = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
       else
       {
           // Convert System.SecureString to Pointer
           IntPtr unmanagedBytes = Marshal.SecureStringToGlobalAllocAnsi(secureTextBox1.SecureText);
           try
           {
               // You have to mark your application to allow unsafe code
               // Enable it at Project's Properties > Build
               unsafe
               {
                   byte* byteArray = (byte*)unmanagedBytes.ToPointer();

                   // Find the end of the string
                   byte* pEnd = byteArray;
                   while (*pEnd++ != 0) { }
                   // Length is effectively the difference here (note we're 1 past end)
                   int length = (int)((pEnd - byteArray) - 1);

                   ba = new byte[length];

                   for (int i = 0; i < length; ++i)
                   {
                       // Work with data in byte array as necessary, via pointers, here
                       byte dataAtIndex = *(byteArray + i);
                       ba[i] = dataAtIndex;
                   }
               }
           }
           finally
           {
               // This will completely remove the data from memory
               Marshal.ZeroFreeGlobalAllocAnsi(unmanagedBytes);
           }
       }
Posted
Comments
Richard MacCutchan 19-Sep-14 4:33am    
The message is telling you what is wrong. You are trying to use a class but you have not included its reference in the project, or a using statement in your source code.
Member 11063279 19-Sep-14 6:26am    
who can i find it??
Richard MacCutchan 19-Sep-14 9:41am    
Find what? You are trying to use a class that is not included in your project. Add the reference and using statement as required.
Tejas Vaishnav 19-Sep-14 4:50am    
From you exception message, you can identify your error, as you are trying to use Secure Text property of your text box. But you project is either missing any reference or your are trying to access invalid property, that's why you got this issue.
Member 11063279 19-Sep-14 6:26am    
but I'm unable to find the error, will you help me?

secureTextBox1.SecureText


secutreTextBox1 is a TextBox. TextBoxes do not have a method named SecureText. If you got this code from some website you'll have to contact them.
 
Share this answer
 
You have to include a declaration of the Class SecureTextBox in your source code. SecureTextBox is not a standard part of the Microsoft .NET Framework.

Here is one implementation that I found using Google search:
DonaqLLC/dnq.securetextboxcontrol[^]

Then, instead of putting a TextBox on your Windows Form, you put a SecureTextBox on your Windows form.

You add a SecureTextBox to your Windows Form Class with C# code similar to this:
C#
// In the global variable declaration area of your Windows Form Class
internal SecureTextBox secureTextBox1;

C#
// In the Load event of your Windows Form place this code:
this.secureTextBox1 = new SecureTextBox();
this.secureTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.secureTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.secureTextBox1.Enabled = true;
this.secureTextBox1.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
// Set Location property to indicate where on the form secureTextBox1 should be located
this.secureTextBox1.Location = new System.Drawing.Point(800, 565);
this.secureTextBox1.Name = "secureTextBox1";
// Set Size property to indicate the size of secureTextBox1
this.secureTextBox1.Size = new System.Drawing.Size(208, 29);
// Set TabIndex property
this.secureTextBox1.TabIndex = 3;
this.secureTextBox1.TabStop = true;
this.Controls.Add(this.secureTextBox1);

Note: I have not tested this myself.
 
Share this answer
 
v3
Comments
Member 11063279 19-Sep-14 14:09pm    
it's really good, but who can i add SecureTextBox instead of TextBox?? please explain me briefly ?? i really need to know it :(
Mike Meinz 19-Sep-14 17:23pm    
I modified the solution to include some sample code. I have not tested this code and I am not an expert in this. I found the answers by reading the Microsoft documentation and via Google search. I hope this helps you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900