Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows API
  4. In the newbie world again...

In the newbie world again...

Scheduled Pinned Locked Moved Windows API
securityhelptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kingletas
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • K kingletas

      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

      J Offline
      J Offline
      Justin Perez
      wrote on last edited by
      #2

      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!

      K 1 Reply Last reply
      0
      • J Justin Perez

        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!

        K Offline
        K Offline
        kingletas
        wrote on last edited by
        #3

        Thank you so much. There is a lot left to learn for this rookie!!!

        Luis E Tineo S

        J 1 Reply Last reply
        0
        • K kingletas

          Thank you so much. There is a lot left to learn for this rookie!!!

          Luis E Tineo S

          J Offline
          J Offline
          Justin Perez
          wrote on last edited by
          #4

          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")

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups