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 Soapbox
  4. WebMatrix - SimpleMembershipProvider Class

WebMatrix - SimpleMembershipProvider Class

Scheduled Pinned Locked Moved The Soapbox
databasesecurityquestion
13 Posts 6 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.
  • J Offline
    J Offline
    Jammer 0
    wrote on last edited by
    #1

    I've just been looking at the source for this and discovered this method. Not the best code I've seen and was wondering what others thought?

        public override void AddUsersToRoles(string\[\] usernames, string\[\] roleNames)
        {
            if (!InitializeCalled)
            {
                PreviousProvider.AddUsersToRoles(usernames, roleNames);
            }
            else
            {
                using (var db = ConnectToDatabase())
                {
                    long userCount = usernames.Length;
                    long roleCount = roleNames.Length;
                    List userIds = GetUserIdsFromNames(db, usernames);
                    List roleIds = GetRoleIdsFromNames(db, roleNames);
    
                    // Generate a INSERT INTO for each userid/rowid combination, where userIds are the first params, and roleIds follow
                    for (int uId = 0; uId < userCount; uId++)
                    {
                        for (int rId = 0; rId < roleCount; rId++)
                        {
                            if (IsUserInRole(usernames\[uId\], roleNames\[rId\]))
                            {
                                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "WebDataResources.SimpleRoleProvder\_UserAlreadyInRole", usernames\[uId\], roleNames\[rId\]));
                            }
    
                            // REVIEW: is there a way to batch up these inserts?
                            long rows = db.Execute("INSERT INTO " + UsersInRoleTableName + " (UserId, RoleId) VALUES (" + userIds\[uId\] + "," + roleIds\[rId\] + "); ");
                            if (rows != 1)
                            {
                                throw new ProviderException("WebDataResources.Security\_DbFailure");
                            }
                        }
                    }
                }
            }
        }
    

    Jammer

    L M P 3 Replies Last reply
    0
    • J Jammer 0

      I've just been looking at the source for this and discovered this method. Not the best code I've seen and was wondering what others thought?

          public override void AddUsersToRoles(string\[\] usernames, string\[\] roleNames)
          {
              if (!InitializeCalled)
              {
                  PreviousProvider.AddUsersToRoles(usernames, roleNames);
              }
              else
              {
                  using (var db = ConnectToDatabase())
                  {
                      long userCount = usernames.Length;
                      long roleCount = roleNames.Length;
                      List userIds = GetUserIdsFromNames(db, usernames);
                      List roleIds = GetRoleIdsFromNames(db, roleNames);
      
                      // Generate a INSERT INTO for each userid/rowid combination, where userIds are the first params, and roleIds follow
                      for (int uId = 0; uId < userCount; uId++)
                      {
                          for (int rId = 0; rId < roleCount; rId++)
                          {
                              if (IsUserInRole(usernames\[uId\], roleNames\[rId\]))
                              {
                                  throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "WebDataResources.SimpleRoleProvder\_UserAlreadyInRole", usernames\[uId\], roleNames\[rId\]));
                              }
      
                              // REVIEW: is there a way to batch up these inserts?
                              long rows = db.Execute("INSERT INTO " + UsersInRoleTableName + " (UserId, RoleId) VALUES (" + userIds\[uId\] + "," + roleIds\[rId\] + "); ");
                              if (rows != 1)
                              {
                                  throw new ProviderException("WebDataResources.Security\_DbFailure");
                              }
                          }
                      }
                  }
              }
          }
      

      Jammer

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Jammer wrote:

      and was wondering what others thought?

      I think you missed that bit in bold red letters at the top of this page.

      Use the best guess

      J 1 Reply Last reply
      0
      • J Jammer 0

        I've just been looking at the source for this and discovered this method. Not the best code I've seen and was wondering what others thought?

            public override void AddUsersToRoles(string\[\] usernames, string\[\] roleNames)
            {
                if (!InitializeCalled)
                {
                    PreviousProvider.AddUsersToRoles(usernames, roleNames);
                }
                else
                {
                    using (var db = ConnectToDatabase())
                    {
                        long userCount = usernames.Length;
                        long roleCount = roleNames.Length;
                        List userIds = GetUserIdsFromNames(db, usernames);
                        List roleIds = GetRoleIdsFromNames(db, roleNames);
        
                        // Generate a INSERT INTO for each userid/rowid combination, where userIds are the first params, and roleIds follow
                        for (int uId = 0; uId < userCount; uId++)
                        {
                            for (int rId = 0; rId < roleCount; rId++)
                            {
                                if (IsUserInRole(usernames\[uId\], roleNames\[rId\]))
                                {
                                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "WebDataResources.SimpleRoleProvder\_UserAlreadyInRole", usernames\[uId\], roleNames\[rId\]));
                                }
        
                                // REVIEW: is there a way to batch up these inserts?
                                long rows = db.Execute("INSERT INTO " + UsersInRoleTableName + " (UserId, RoleId) VALUES (" + userIds\[uId\] + "," + roleIds\[rId\] + "); ");
                                if (rows != 1)
                                {
                                    throw new ProviderException("WebDataResources.Security\_DbFailure");
                                }
                            }
                        }
                    }
                }
            }
        

        Jammer

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        I want to know what led you to posting this in the SB, an article writer, obviously experienced in using CP and you post code into the one area where people can legitimately be rude about it (a more gentle attitude now exists in the Lounge). Consider yourself thoroughly chastised, ridiculed and insulted, back to the c# forum with you I say!

        Never underestimate the power of human stupidity RAH

        S J 3 Replies Last reply
        0
        • M Mycroft Holmes

          I want to know what led you to posting this in the SB, an article writer, obviously experienced in using CP and you post code into the one area where people can legitimately be rude about it (a more gentle attitude now exists in the Lounge). Consider yourself thoroughly chastised, ridiculed and insulted, back to the c# forum with you I say!

          Never underestimate the power of human stupidity RAH

          S Offline
          S Offline
          Sentenryu
          wrote on last edited by
          #4

          strange thing, i was on "the weird and wonderful", clicked on the link to the first page and ended up on the soapbox, maybe the same happened to him?

          I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"

          V 1 Reply Last reply
          0
          • S Sentenryu

            strange thing, i was on "the weird and wonderful", clicked on the link to the first page and ended up on the soapbox, maybe the same happened to him?

            I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"

            V Offline
            V Offline
            vonb
            wrote on last edited by
            #5

            Working normally here..

            The signature is in building process.. Please wait...

            S 1 Reply Last reply
            0
            • V vonb

              Working normally here..

              The signature is in building process.. Please wait...

              S Offline
              S Offline
              Sentenryu
              wrote on last edited by
              #6

              I could not reproduce, so i didn't report it. Must be some company police getting in the way, i can't even open CP on IE here, as the forums expand all posts and all ajax is replace by normal posts, so i'll blame this weirdness on company police as well.

              I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"

              V 1 Reply Last reply
              0
              • S Sentenryu

                I could not reproduce, so i didn't report it. Must be some company police getting in the way, i can't even open CP on IE here, as the forums expand all posts and all ajax is replace by normal posts, so i'll blame this weirdness on company police as well.

                I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"

                V Offline
                V Offline
                vonb
                wrote on last edited by
                #7

                Sentenryu wrote:

                i can't even open CP on IE here

                Than blame ..MS (I just have IE here on a Terminal server, so cannot test any other browsers, stupid company policy..)

                The signature is in building process.. Please wait...

                1 Reply Last reply
                0
                • J Jammer 0

                  I've just been looking at the source for this and discovered this method. Not the best code I've seen and was wondering what others thought?

                      public override void AddUsersToRoles(string\[\] usernames, string\[\] roleNames)
                      {
                          if (!InitializeCalled)
                          {
                              PreviousProvider.AddUsersToRoles(usernames, roleNames);
                          }
                          else
                          {
                              using (var db = ConnectToDatabase())
                              {
                                  long userCount = usernames.Length;
                                  long roleCount = roleNames.Length;
                                  List userIds = GetUserIdsFromNames(db, usernames);
                                  List roleIds = GetRoleIdsFromNames(db, roleNames);
                  
                                  // Generate a INSERT INTO for each userid/rowid combination, where userIds are the first params, and roleIds follow
                                  for (int uId = 0; uId < userCount; uId++)
                                  {
                                      for (int rId = 0; rId < roleCount; rId++)
                                      {
                                          if (IsUserInRole(usernames\[uId\], roleNames\[rId\]))
                                          {
                                              throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "WebDataResources.SimpleRoleProvder\_UserAlreadyInRole", usernames\[uId\], roleNames\[rId\]));
                                          }
                  
                                          // REVIEW: is there a way to batch up these inserts?
                                          long rows = db.Execute("INSERT INTO " + UsersInRoleTableName + " (UserId, RoleId) VALUES (" + userIds\[uId\] + "," + roleIds\[rId\] + "); ");
                                          if (rows != 1)
                                          {
                                              throw new ProviderException("WebDataResources.Security\_DbFailure");
                                          }
                                      }
                                  }
                              }
                          }
                      }
                  

                  Jammer

                  P Offline
                  P Offline
                  Pasan Eeriyagama
                  wrote on last edited by
                  #8

                  It's the The Soapbox baby.. ;)

                  1 Reply Last reply
                  0
                  • M Mycroft Holmes

                    I want to know what led you to posting this in the SB, an article writer, obviously experienced in using CP and you post code into the one area where people can legitimately be rude about it (a more gentle attitude now exists in the Lounge). Consider yourself thoroughly chastised, ridiculed and insulted, back to the c# forum with you I say!

                    Never underestimate the power of human stupidity RAH

                    J Offline
                    J Offline
                    Jammer 0
                    wrote on last edited by
                    #9

                    I was thinking it more of a soapbox thing as I'm not asking a programming question about the code. I don't want to ask any programming questions about the code. I'm just amazed at how botched an inefficient the code is in places. Scores of people will be using the MebMatrix code in their projects and some of it really is of questionable quality. You're right I am an experienced CP person which is why it didn't feel appropriate to post this in the C# form since I have no overtly programming related question about the code. Sorry.

                    Jammer

                    1 Reply Last reply
                    0
                    • L Lost User

                      Jammer wrote:

                      and was wondering what others thought?

                      I think you missed that bit in bold red letters at the top of this page.

                      Use the best guess

                      J Offline
                      J Offline
                      Jammer 0
                      wrote on last edited by
                      #10

                      I was looking for the coding horrors forum to be honest ... I couldn't find it anymore ...

                      Jammer

                      L 1 Reply Last reply
                      0
                      • J Jammer 0

                        I was looking for the coding horrors forum to be honest ... I couldn't find it anymore ...

                        Jammer

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        It's the next one down in the TreeView on the left[^].

                        Use the best guess

                        J 1 Reply Last reply
                        0
                        • L Lost User

                          It's the next one down in the TreeView on the left[^].

                          Use the best guess

                          J Offline
                          J Offline
                          Jammer 0
                          wrote on last edited by
                          #12

                          Ahhh ... I just read the explanation for that forum as well ... duh! Sorry guys.

                          Jammer

                          1 Reply Last reply
                          0
                          • M Mycroft Holmes

                            I want to know what led you to posting this in the SB, an article writer, obviously experienced in using CP and you post code into the one area where people can legitimately be rude about it (a more gentle attitude now exists in the Lounge). Consider yourself thoroughly chastised, ridiculed and insulted, back to the c# forum with you I say!

                            Never underestimate the power of human stupidity RAH

                            J Offline
                            J Offline
                            Jammer 0
                            wrote on last edited by
                            #13

                            Yeah, my bad. I was looking for the Coding Horrors forum but couldn't find it. I just read the explanation text for the WAW forum. I haven't been on CP for ages and didn't realise it had been renamed. Sorry.

                            Jammer

                            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