In the newbie world again...
-
hey all, I thought i had this project well maded and all that but now i realized that i have some security flaws and i surely don't know how to fix it: 1-) When i hit Alt+F4 the form closes. I would like to add an OnClosing event to stop the form from being close unless an authorized user wants to close it. How could i add it? 2-)I want to verify that the current user is not a restricted user so the application can be run. I need fully access for the application to be run properly. 3-) I would like to use the windows user and passwords to verify that the current user is really identified. Thanks all again!!!
Luis E Tineo S
-
hey all, I thought i had this project well maded and all that but now i realized that i have some security flaws and i surely don't know how to fix it: 1-) When i hit Alt+F4 the form closes. I would like to add an OnClosing event to stop the form from being close unless an authorized user wants to close it. How could i add it? 2-)I want to verify that the current user is not a restricted user so the application can be run. I need fully access for the application to be run properly. 3-) I would like to use the windows user and passwords to verify that the current user is really identified. Thanks all again!!!
Luis E Tineo S
kingletas wrote:
1-) When i hit Alt+F4 the form closes. I would like to add an OnClosing event to stop the form from being close unless an authorized user wants to close it. How could i add it?
Is this a C# project? If so, handle the FormClosing event. Your event would look like this:
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if(user != "authorizied user") { e.Cancel = true; MessageBox.Show("You are not an authorized user, you cannot close the application!"); } }
The
FormClosingEventArgs
type can override the closing of the form. If type has been declared(e),e.Cancel = true;
will stop the form from closing.e.Cancel = false;
will let the form close. Also, in your if statement there is another thing you can do to ensure that only the user can close the form is by throwing another condition in your if statement. It could look like this:if ((user != "authorizied user") && (CloseReason.UserClosing != e.CloseReason))
kingletas wrote:
2-)I want to verify that the current user is not a restricted user so the application can be run. I need fully access for the application to be run properly.
You would do this in your Program.cs's
Main()
method. It could look like this:namespace YourNameSpace { class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (true == isUserAnAuthorizedUserMethod("SomeUserName") { YourMainForm frmMain = new YourMainForm(); Application.Run(); // Your loading condition has been met, load the application } else { Application.Exit(); // Your loading condition has not been met, shut down the application } } }
kingletas wrote:
3-) I would like to use the windows user and passwords to verify that the current user is really identified.
I don't really know how you could do that off the top of my head. If I can think of anything I'll reply to this post. Hope all that helps!
-
kingletas wrote:
1-) When i hit Alt+F4 the form closes. I would like to add an OnClosing event to stop the form from being close unless an authorized user wants to close it. How could i add it?
Is this a C# project? If so, handle the FormClosing event. Your event would look like this:
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if(user != "authorizied user") { e.Cancel = true; MessageBox.Show("You are not an authorized user, you cannot close the application!"); } }
The
FormClosingEventArgs
type can override the closing of the form. If type has been declared(e),e.Cancel = true;
will stop the form from closing.e.Cancel = false;
will let the form close. Also, in your if statement there is another thing you can do to ensure that only the user can close the form is by throwing another condition in your if statement. It could look like this:if ((user != "authorizied user") && (CloseReason.UserClosing != e.CloseReason))
kingletas wrote:
2-)I want to verify that the current user is not a restricted user so the application can be run. I need fully access for the application to be run properly.
You would do this in your Program.cs's
Main()
method. It could look like this:namespace YourNameSpace { class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (true == isUserAnAuthorizedUserMethod("SomeUserName") { YourMainForm frmMain = new YourMainForm(); Application.Run(); // Your loading condition has been met, load the application } else { Application.Exit(); // Your loading condition has not been met, shut down the application } } }
kingletas wrote:
3-) I would like to use the windows user and passwords to verify that the current user is really identified.
I don't really know how you could do that off the top of my head. If I can think of anything I'll reply to this post. Hope all that helps!
-
kingletas wrote:
Thank you so much.
Yeah, you bet. I'm glad I could help.
kingletas wrote:
There is a lot left to learn for this rookie!!!
Yeah, same for me :)
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")