homemade authentication function

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default homemade authentication function

    I’m making an authentication script with groups and roles. This function
    checks if the groups the user belongs to specified groups and compares
    them to the groups required. However, since this is a loop, the function
    doesn’t return true or false as expected. If I call the function and
    require 3 groups, and the user belongs to only one of them, he is still
    accepted. Is this method right thinking? Should I make the function stop
    somehow when it returns false for the first time? All suggestions and
    comments are appreciated. Thanks.

    This is the function:

    function require_groups() {
    if (!isset($this->user['groups'])) {
    $this->user['groups'] =
    $this->get_user_groups($this->id);
    }
    $groups = func_get_args();
    foreach ($groups as $value) {
    if
    (!isset($this->user['groups'][$value]) ||
    !$this->user['groups'][$value]) {
    return false;
    }
    else{
    return true;
    }
    }
    }

    And I call it like this: require_groups(“admins”,
    “moderators”,“members”);
    This returns true.

    Kveðja,
    Sævar Öfjörð
    [email]ofjord@reddast.is[/email]
    þetta reddast - hönnunarlausnir

    <file:///C:\Documents%20and%20Settings\S%E6var\Application% 20Data\Micros
    oft\Signatures\www.reddast.is> [url]www.reddast.is[/url]


    SævË Ölêöyp Guest

  2. Similar Questions and Discussions

    1. Integration with homemade software
      I am building a content management system. There will be links to all of our files which can open any of them in a browser window. I would also like...
    2. Accessing htm files without authentication (forms authentication)
      I have application with forms authentication. All works fine. When user opens .aspx file gets login form, login and then get the .aspx page. But...
    3. Homemade Patterns
      I want to make my own patterns, which I'd figured out how to do in 4.0, but every since I've used 9.0 I've not had success.
    4. Authentication ticket, cookieless, forms authentication?
      Hi. I want to use Forms Authentication, cookieless. The issue is setting the Authentication Ticket without using cookies (!) That is, the...
    5. Homemade website traffic tracking reports?
      I'm looking at the various free and paid website traffic tracking options available. None seem to do quiet what I want and the rest are too...
  3. #2

    Default Re: homemade authentication function

    i think the problem isn't only your 'return false' but also your 'return
    true' in your first loop through your foreach will definetly a 'return' be
    passed. and return means return a value AND stop the function. not?

    try it this way:

    foreach ($groups as $value)
    {
    if(!isset($this->user['groups'][$value]) ||
    !$this->user['groups'][$value])
    {
    return false;
    }
    }
    return true;

    ciao SVEN

    SævË Ölêöyp wrote:
    > I'm making an authentication script with groups and roles. This
    > function checks if the groups the user belongs to specified groups
    > and compares them to the groups required. However, since this is a
    > loop, the function doesn't return true or false as expected. If I
    > call the function and require 3 groups, and the user belongs to only
    > one of them, he is still accepted. Is this method right thinking?
    > Should I make the function stop somehow when it returns false for the
    > first time? All suggestions and comments are appreciated. Thanks.
    >
    > This is the function:
    >
    > function require_groups() {
    > if (!isset($this->user['groups'])) {
    > $this->user['groups'] =
    > $this->get_user_groups($this->id);
    > }
    > $groups = func_get_args();
    > foreach ($groups as $value) {
    > if
    > (!isset($this->user['groups'][$value]) ||
    > !$this->user['groups'][$value]) {
    > return false;
    > }
    > else{
    > return true;
    > }
    > }
    > }
    >
    > And I call it like this: require_groups("admins",
    > "moderators","members");
    > This returns true.
    >
    > Kveðja,
    > Sævar Öfjörð
    > [email]ofjord@reddast.is[/email]
    > þetta reddast - hönnunarlausnir
    >
    > <file:///C:\Documents%20and%20Settings\S%E6var\Application% 20Data\Micros
    > oft\Signatures\www.reddast.is> [url]www.reddast.is[/url]

    Sven Guest

  4. #3

    Default RE: [PHP] Re: homemade authentication function [SOLVED]

    Hey, thanks Sven. This seems to be working for me.

    -----Original Message-----
    From: sven [mailto:svenie@gmx.li]
    Sent: 23. júlí 2003 10:35
    To: [email]php-general@lists.php.net[/email]
    Subject: [PHP] Re: homemade authentication function

    i think the problem isn't only your 'return false' but also your 'return
    true' in your first loop through your foreach will definetly a 'return'
    be
    passed. and return means return a value AND stop the function. not?

    try it this way:

    foreach ($groups as $value)
    {
    if(!isset($this->user['groups'][$value]) ||
    !$this->user['groups'][$value])
    {
    return false;
    }
    }
    return true;

    ciao SVEN

    SævË Ölêöyp wrote:
    > I'm making an authentication script with groups and roles. This
    > function checks if the groups the user belongs to specified groups
    > and compares them to the groups required. However, since this is a
    > loop, the function doesn't return true or false as expected. If I
    > call the function and require 3 groups, and the user belongs to only
    > one of them, he is still accepted. Is this method right thinking?
    > Should I make the function stop somehow when it returns false for the
    > first time? All suggestions and comments are appreciated. Thanks.
    >
    > This is the function:
    >
    > function require_groups() {
    > if (!isset($this->user['groups'])) {
    > $this->user['groups'] =
    > $this->get_user_groups($this->id);
    > }
    > $groups = func_get_args();
    > foreach ($groups as $value) {
    > if
    > (!isset($this->user['groups'][$value]) ||
    > !$this->user['groups'][$value]) {
    > return false;
    > }
    > else{
    > return true;
    > }
    > }
    > }
    >
    > And I call it like this: require_groups("admins",
    > "moderators","members");
    > This returns true.
    >
    > Kveðja,
    > Sævar Öfjörð
    > ofjord@reddast.is
    > þetta reddast - hönnunarlausnir
    >
    >
    <file:///C:\Documents%20and%20Settings\S%E6var\Application% 20Data\Micros
    > oft\Signatures\www.reddast.is> www.reddast.is


    --
    PHP General Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php


    SævË Ölêöyp Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139