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. Other Discussions
  3. The Weird and The Wonderful
  4. Access granted!

Access granted!

Scheduled Pinned Locked Moved The Weird and The Wonderful
securityquestion
15 Posts 9 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.
  • G GibbleCH

    Multiple returns are not gotos and are not a bad design practice. Guard conditions are actually favored over nesting if's

    L Offline
    L Offline
    Lutoslaw
    wrote on last edited by
    #4

    You are right about guard condition. My note was general -- do not use 'return' like 'goto' (jumping from the middle of method).

    Greetings - Jacek

    R 1 Reply Last reply
    0
    • L Lutoslaw

      It is not necessarily a horror if it was found in a debug/dev build. I do it in similar way, too. Of course you have to remember to remove it for release builds (or use #if DEBUG clause). Note: don't use GOTO (multiple returns are gotos too)

      Greetings - Jacek

      T Offline
      T Offline
      TorstenH
      wrote on last edited by
      #5

      This is Java code. Returning a value "null" is not the best idea, but it's a invalid value one can identify as such. I actually often return values in that way:

      switch(key){
      case x: return a;
      case y: return b;
      default: return null;
      }

      It's pretty handsome and easy to maintain. regards Torsten

      I never finish anyth...

      L 1 Reply Last reply
      0
      • T TorstenH

        This is Java code. Returning a value "null" is not the best idea, but it's a invalid value one can identify as such. I actually often return values in that way:

        switch(key){
        case x: return a;
        case y: return b;
        default: return null;
        }

        It's pretty handsome and easy to maintain. regards Torsten

        I never finish anyth...

        L Offline
        L Offline
        Lutoslaw
        wrote on last edited by
        #6

        Since the Nullable<> thing was introduced, it seems that MS encourages developers to use null as a "special" and possibly meaningful value. Personally I don't have a strong opinion on that, but often after I declared sth as T? I had to change it to T due to interopability issues and too many not-null checks.

        Greetings - Jacek

        1 Reply Last reply
        0
        • L Lutoslaw

          You are right about guard condition. My note was general -- do not use 'return' like 'goto' (jumping from the middle of method).

          Greetings - Jacek

          R Offline
          R Offline
          Rob Grainger
          wrote on last edited by
          #7

          That depends a lot on your language. Its a common (and safe) technique in C++ using RAII techniques.

          1 Reply Last reply
          0
          • T TorstenH

            Ever wondered how those password dialogs work like? Here is a small sneak under the hood:

            final PasswordDialog pwd = new PasswordDialog(ApplicationWorkbenchWindowAdvisor.getShell());
            if (pwd.open() == Window.OK) {
            ConnectionManager.password = AccountManager.getGeneralStore().getString(
            "UA.Account.Security.sec_pass"
            );
            }
            else {
            return null;
            }

            Security at it's best. At least does the string from the preferences store just fit if you've got the right username :omg: regards Torsten

            I never finish anyth...

            B Offline
            B Offline
            Br Bill
            wrote on last edited by
            #8

            If you're going to say something is bad, could you at least explain to rookie doofuses like me why it's bad? Due to my lack of experience, I look at your code and I have no idea what the problem is. Furthermore, none of the comments here helps. Explain to me like I'm a complete idiot (which I occasionally am).

            G E T 3 Replies Last reply
            0
            • B Br Bill

              If you're going to say something is bad, could you at least explain to rookie doofuses like me why it's bad? Due to my lack of experience, I look at your code and I have no idea what the problem is. Furthermore, none of the comments here helps. Explain to me like I'm a complete idiot (which I occasionally am).

              G Offline
              G Offline
              Gary Huck
              wrote on last edited by
              #9

              Seems to me what they're talking about is the use of null as a return value. "They" don't seem to like it. Seems to me there's lots of "personal preferences" in a lot of threads found on this forum. To me, returning null is just fine; as an old database guy, null proves to be a very handy and very real data type/value.

              1 Reply Last reply
              0
              • B Br Bill

                If you're going to say something is bad, could you at least explain to rookie doofuses like me why it's bad? Due to my lack of experience, I look at your code and I have no idea what the problem is. Furthermore, none of the comments here helps. Explain to me like I'm a complete idiot (which I occasionally am).

                E Offline
                E Offline
                englebart
                wrote on last edited by
                #10

                As to the return thing... Camp 1 says, when writing a method/function, you should have one entry point and one exit point. For languages that use return to exit the method, this implies a single return at the end of the method/function. Using this model sometimes involves multiple nested if statements. Camp 2 might say I like to validate all preconditions and immediately return if something appears amiss, but then I have one return at the bottom for the real answer. Camp 3 might say, I use assert() for things like Camp 2 does with returns, but I still have one return at the bottom. Camp 4 might say, just throw a return in wherever it makes sense. Camp X, might pick and choose what they want from other camps.

                B 1 Reply Last reply
                0
                • E englebart

                  As to the return thing... Camp 1 says, when writing a method/function, you should have one entry point and one exit point. For languages that use return to exit the method, this implies a single return at the end of the method/function. Using this model sometimes involves multiple nested if statements. Camp 2 might say I like to validate all preconditions and immediately return if something appears amiss, but then I have one return at the bottom for the real answer. Camp 3 might say, I use assert() for things like Camp 2 does with returns, but I still have one return at the bottom. Camp 4 might say, just throw a return in wherever it makes sense. Camp X, might pick and choose what they want from other camps.

                  B Offline
                  B Offline
                  Br Bill
                  wrote on last edited by
                  #11

                  Thanks!

                  1 Reply Last reply
                  0
                  • B Br Bill

                    If you're going to say something is bad, could you at least explain to rookie doofuses like me why it's bad? Due to my lack of experience, I look at your code and I have no idea what the problem is. Furthermore, none of the comments here helps. Explain to me like I'm a complete idiot (which I occasionally am).

                    T Offline
                    T Offline
                    TorstenH
                    wrote on last edited by
                    #12

                    There is a dialog opened - a password-dialog. When it returns OK (dialog is confirmed / left with "OK" button) the app not uses the entered password, but refers to some preference stored before. Passwords which are entered by the user in a customers application, may never be written to files - no matter if ASCII, binary or whatever. It took me a couple of hours to verify that no password is stored in that application and no password is read at any time. A password must always be kept in the RAM and disposed when the application is shut down. Also the stored password in the database should be encrypted. regards Torsten

                    I never finish anyth...

                    B P 2 Replies Last reply
                    0
                    • T TorstenH

                      There is a dialog opened - a password-dialog. When it returns OK (dialog is confirmed / left with "OK" button) the app not uses the entered password, but refers to some preference stored before. Passwords which are entered by the user in a customers application, may never be written to files - no matter if ASCII, binary or whatever. It took me a couple of hours to verify that no password is stored in that application and no password is read at any time. A password must always be kept in the RAM and disposed when the application is shut down. Also the stored password in the database should be encrypted. regards Torsten

                      I never finish anyth...

                      B Offline
                      B Offline
                      Br Bill
                      wrote on last edited by
                      #13

                      Wow, from looking at that piece of code, I'd never know anything was awry. Without me looking up a bunch of APIs, I'd never have a clue it was doing any of that wrong.

                      1 Reply Last reply
                      0
                      • T TorstenH

                        There is a dialog opened - a password-dialog. When it returns OK (dialog is confirmed / left with "OK" button) the app not uses the entered password, but refers to some preference stored before. Passwords which are entered by the user in a customers application, may never be written to files - no matter if ASCII, binary or whatever. It took me a couple of hours to verify that no password is stored in that application and no password is read at any time. A password must always be kept in the RAM and disposed when the application is shut down. Also the stored password in the database should be encrypted. regards Torsten

                        I never finish anyth...

                        P Offline
                        P Offline
                        patbob
                        wrote on last edited by
                        #14

                        If you're really worried about security, don't forget to overwrite that password in RAM immediately when you're done with it. Wouldn't want that cleartext password to get paged to disk.

                        patbob

                        M 1 Reply Last reply
                        0
                        • P patbob

                          If you're really worried about security, don't forget to overwrite that password in RAM immediately when you're done with it. Wouldn't want that cleartext password to get paged to disk.

                          patbob

                          M Offline
                          M Offline
                          Michael D OConnor
                          wrote on last edited by
                          #15

                          You'd have to physically find it first.

                          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