|
While I am not sure this will fit what you need I do something similar in one of the applications I develop and you may be able to tweak this.
Basically this application has functionality within it that could feasible be very destructive in the wrong hands. As a result of this I need to ensure that the user sat at the machine is the actual user that is logged on. In order to do this when the application opens it prompts them to enter their windows authentication information.
Internally the code uses the following:
const int LOGON32_LOGON_INTERACTIVE = 2;
const int LOGON32_PROVIDER_DEFAULT = 0;
[DllImport("advapi32.dll", SetLastError=true)]
private static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
private void DoLogonCheck()
{
this.logonAttemptCount++;
IntPtr phToken = IntPtr.Zero;
bool logonRes = LogonUser(
txtDomainUserName.Text,
txtDomainName.Text,
txtDomainPassword.Text,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
ref phToken);
if (logonRes)
{
this.DialogResult = DialogResult.OK;
this.domainUserName = txtDomainUserName.Text;
this.domainName = txtDomainName.Text;
}
else if ((!logonRes) && (this.logonAttemptCount < this.maxLogonAttempts))
{
txtDomainPassword.Text = string.Empty;
txtDomainPassword.Focus();
}
else if ((!logonRes) && (this.logonAttemptCount >= this.maxLogonAttempts))
{
System.Windows.Forms.Application.Exit();
}
}
Externally to this method the code also checks that the given user name is the same user that is under the Environment.UserName object.
As an additional level of security the form that results from successful authentication has a timeout that will close it after X seconds of inactivity. This means that if the user logs in and then gets up an walks away the application isnt open to any passer by.
In theory I believe that this code could also be used to check the logon for a user that is not currently logged on, however I have never used it that way so I cannot say for certain
|
|
|
|
|
Hi,
Thanks for ur Valuable reply.while im using ur code im getting the error on
this.logonAttemptCount++;
.
.
.
this.domainUserName = txtDomainUserName.Text;
this.domainName = txtDomainName.Text;
.
.
else if ((!logonRes) && (this.logonAttemptCount < this.maxLogonAttempts))
.
.
else if ((!logonRes) && (this.logonAttemptCount >= this.maxLogonAttempts))
Im getting error on these lines as "does not contain definition for 'logonAttemptCount'" and "does not contain definition for 'domainUserName'" and "does not contain definition for 'domainName'"...How to i solve this did i need to add any references other than this
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.DirectoryServices;
using System.Runtime.InteropServices;
using System.Web.Security;
using System.Security.Principal;
If yes, give me the detail and give me a solution to the error..plz
rgrds
Kanna..
|
|
|
|
|
those three variables are class level items, so if you want to use logon attempt counts and need to keep a record of the entered user/domain name you will need them (depending on yor class design)
As an example:
using....
using....
using....
namespace Widgets
{
class LogonCheck
{
private string domainUserName;
private string domainName;
private int logonAttemptCount;
public LogonCheck()
{
this.domainUserName = string.Empty;
this.domainName = string.Empty;
this.logonAttemptCount = 0;
}
public DoLogonCheck()
{
}
}
}
That about covers it, however depending on your design you may or may not need these or it may be better to declare these as static
|
|
|
|
|
How can I use Formula in crystal Report 9
|
|
|
|
|
Hi.
I have an auto-increment database field with 5 digits. (example. "00001", "00002", "00003")
But every time i query it using C#, and place it in text boxes or in labels, it always removes the zeros, so I always end up with just "1", "2", "3", etc.
I'm currently using microsoft access 2003. The error also occurred when I used mySQL.
Anyone know how to set form objects to recognize the zeros in the values?
Thanks in advance.
|
|
|
|
|
Its only an error if the value is a string. If it's a number at any point in the process, the 0s are meaningless, and therefore discarded.
You can use string.Format to format a string to have as many zeros as it needs to fit this format.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi every one! I've create my own C++ class and push it to the dll. I need to get only one function from it. It fills many variables of this class. I need to get them, but i don know how. One of this var is vector<string> how can i get this data? I have read the article about calling functions from dll, but i can't get data from my var.
Thanks.
|
|
|
|
|
A vector is a C++ class, you'd need to push out an array ( which is what the vector is wrapping ) instead.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi all
i have got two forms one up on the other..
now if i click on the form which is behind the form which is on top is going behind..
i dont want that to happen...
i want the form which is in front should take info. and then active the form behind....
please help me for the necessary..
thanks bye
|
|
|
|
|
I think you need to show a from on top. Considering form1 is the Form object that you want to keep on top of form2
use form1.TopMost = true before calling form1.Show() or form1.ShowDialog()
|
|
|
|
|
If form2 is a child of form1, set the owner of form2 to be form1. Then, form2 will always stay above, as achild window should.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I'm create an instance called shtb like this:
public form1()
{
InitializeComponent();
SyntaxHighlightingTextBox shtb = new SyntaxHighlightingTextBox();
...
}
Later in the script, i tried to use the instance shtb like this:
static string strMyOriginalScript = "";
private void form1_Load(object sender, System.EventArgs e)
{
strMyOriginalScript = shtb.Text;
}
When ever i try to build the solution, i keep getting the error:
'Editing Area' does not exist in the current context
Where im i going wrong? Can anyone help me with atleast this?
|
|
|
|
|
I tried editing like this also:
static string strMyOriginalScript = "";
private void form1_Load(object sender, System.EventArgs e)
{
SyntaxHighlightingTextBox shtb;
strMyOriginalScript = shtb.Text;
}
still didn't work... where im i going wrong?
|
|
|
|
|
the problem is with the object not with the string,
define the object outside the constructor, just below the definition of the class
public class form1
{
SyntaxHighlightingTextBox shtb = null;
..................
.............
...
and then in the constructor you initialize the object
public form1()
{
InitializeComponent();
shtb = new SyntaxHighlightingTextBox();
...
Andres
"Learn from the mistakes of others.
You can't live long enough to make them all yourself."
"Failure doesn't mean I'm a failure, It does mean I have not yet succeeded;
Failure doesn't mean that I should give up, It does mean that I should try harder;
Failure doesn't mean that I will never make it, It does mean that I need more practice".
Thank you for helping.
|
|
|
|
|
Latheesan wrote: SyntaxHighlightingTextBox shtb = new SyntaxHighlightingTextBox();
If this is a control, you need to set it's location on the form and add it to the forms Controls collection. Otherwise, it's just a local variable that disappears as soon as it goes out of scope. Even if it was a member, if it's not in the Controls collection, it's not on the form
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Yes, it was a control that was provided from an external .dll
so, i added the dll into my project reference first and then, in the top of the form1.cs, i have this code:
using SyntaxHighlighting;
and iniside the form1_Load(); i have this code now:
Controls.Add(shtb);
Yet, i still get that error "The name 'shtb' does not exist in the current context"
|
|
|
|
|
The error that was pointed out to you is still the case. If you create it in your constructor, locally, then it doesn't exist anymore in your load event. You should call the constructor in your load event. Scratch that. You buy a book on VB.NET, read it, work through it, and start another project when you've learned some basics. If you don't understand variable scoping, you frankly should not be writing code, sorry.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
Hi there
I need to be able to write logs to a network drive, but I cannot get the FileIOPermission to work,
I am using the code below
[CODE]
PermissionSet ps1 = new PermissionSet(PermissionState.None);
ps1.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, m_LogFile));
ps1.Demand();
[/CODE]
but when I try to write to the file I get the following Error
[CODE]
Request for the permission of type System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
[\CODE]
What should I use instead????
Regards
Andres
"Learn from the mistakes of others.
You can't live long enough to make them all yourself."
"Failure doesn't mean I'm a failure, It does mean I have not yet succeeded;
Failure doesn't mean that I should give up, It does mean that I should try harder;
Failure doesn't mean that I will never make it, It does mean that I need more practice".
Thank you for helping.
|
|
|
|
|
I have a UserControl. When I instantiate it the UserControl reads in an image that it uses, it draws it underneath the cursor. If I programmatically add the UserControl to a form and then run the program it works perfect. However if I try to do this via design time support I get an error screen instead of a design time screen, the error is:
"One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes."
The reason for the error is that it can't find my image file, because instead of looking for it in my programs folder it looks for it in the Visual Studio IDE Folder.
"Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\images\tileselect.png'. " Is the exact error I get.
My original idea was to just remove design time rendering of the control, since it works just fine when I run it, but I couldn't figure out how to make it so that a control is not rendered when you use it in design time. Though design-time support is preferred.
Any help on this would be great. I am actually using a combination XNA/Windows Forms but from what I can tell that should have no bearing on the issue.
Source Code At Problem:
tileSelect = Texture2D.FromFile(GraphicsDevice, "images/tileselect.png");
If I remove this line, and the line that draws the sprite, it will work fine in Design time, it even calls the On_Paint event and runs the XNA code to clear the screen, not shown. Is there maybe some way I could rewrite my path so that it would look in my programs directory... No idea, thats why I posted here
Thanks in advance.
--Peter
|
|
|
|
|
Hi,
you can use Component.DesignMode to have another file path (or no file loading)
while in design mode...
|
|
|
|
|
Worked Great, thanks.
--Peter
|
|
|
|
|
Hello.
I have a windows forms application (.NET 3.0)
where I have a user control ( a sort of spine) on a Form (called imaginatively enough MainForm).
In the spine I make a call to a WCF service (in a seperate thread). I need to be able to (from this seperate thread) to call a method (DisplayNotification) on the MainForm and pass it a parameter (or two).
I just can't seem to do this. I am however able (with delegates) to do this with methods/controls on the spine. But unfortunate not the MainForm.
Can someone give me a leg up on this?
Basically:
Spine(usercontrol on MainForm) ->starts thread(WCF service) ->needs to access DisplayNotification() on MainForm.
I tried using FindContol() and even .Parent but I am embarassed to say...
I don't know how to use it. I can get a list of controls that match the control I want. I get it in a the form of ArrayOfFormControls[]. It's just that I don't know how to invoke properties on the say ArrayOfFormControls[0].
Can you point me towards an example? Basically I would prefer to use a METHOD in the MainForm to do my dirty work, rather than use properties on the control itself.
Some have mentioned using reflection, I'm afraid I have no experience with using reflection. Can you point towards an example or tutorial. I have googled it, and come up short....
There has also been talk of passing a reference to the mainform in the constructor of my usercontrol. Any concrete examples?
Thanks!
----------------------------------------
Code is sexy. Go get some.
|
|
|
|
|
Of course U can do that with the help of delegates.
In the main form create a delegate that calls the function in the mainform.
Pass the delegate as a parameter to a public function in the subform(just after creating the usercontrol).
The public function should assign the argument to a local delegate.
So, whenever U wish to call the mainForm function, call the local delegate
after checking for null.
Regards,
Arun Kumar.A
|
|
|
|
|
hi every one,
I am making a Windows application in C# 2.0 and I was trying to give the connection String dynamically to the dataset bcz it would contain sensitive information otherwise. That's bcz I'm using Sql Server Authentication to logon to the database.
@"Data Source=LEOPARD\ATECH;Initial Catalog=KPS;User ID =Rocky;
The password is yet to be given and as long as I dont give it this exception will not stop from comming. The dataset wizard asked the question of including the sensitive info (passwrd) in the connection string but I refused and it said that you'd have to add that programatically on ur own. So there's gotta be a way to do it somehow. Can any buddy plz tell me that?
thanks in advance,
Rocky
|
|
|
|