3

I have uncomment in module loader to load auth, but what I am not understanding is that how to tell auth module that which fields of which table it should use to authenticate? I also didn't find that in userguide in Kohana 3 as I found that userguide for auth module is not present.

So please tell if some one is already using it. And if it use some default fields of some table then how can I modify it?

thanks for reading my question and your effort to answer it.

Kowser
  • 8,123
  • 7
  • 40
  • 63
Hafiz
  • 4,187
  • 12
  • 58
  • 111
  • So you want to use the orm drive? So first enable orm and database module. The database scheme can found here http://jdstraughan.com/post/auth-module-for-kohana-31-using-orm-driver. It is a good tutorial for using the auth module with orm driver, too. The scheme s working for kohana 3.2 too, but i haven't tried the controller examples. – David Stutz Nov 07 '11 at 17:20
  • No, I want to know that what table or table structure do auth module of kohana 3 require? And where I can change it to my own fields and table? – Hafiz Nov 08 '11 at 00:17

2 Answers2

8

Here are the steps for you

  • Uncomment the Auth module in bootstrap.php (you have done it already)
  • in ORM Module, yes in ORM Module you will find auth-schema-mysql.sql & auth-schema-postgresql.sql. Use the one you needed.
  • configure the config file auth.php as needed. Below is the configuration I am using.

    <?php defined('SYSPATH') or die('No direct access allowed.');
    return array(
        'driver'       => 'ORM',
        'hash_method'  => 'sha256',
        'hash_key'     => "ica_hash_key",
        'lifetime'     => Date::MINUTE * 30,
        'session_type' => 'database',
        'session_key'  => 'auth_user',
    );
    
  • set Cookie::$salt in bootstrap.php. Add this line in your bootstrap.php.

    Cookie::$salt = 'YourSecretCookieSalt';
    
  • you are done with Auth module configuration ;)


As you have configured auth module, obviously you have executed the sql script. You will get users, roles, roles_users & users_tokens table created in your database.

Now you can change users table with adding more column. As you are using ORM, Model_User is already there for you which is an ORM :)

So this should be all, i believe.

Kowser
  • 8,123
  • 7
  • 40
  • 63
1

Both the MySQL and PostGreSQL database schemas for the Auth ORM driver can be found in the ORM module. But make sure the length of the password field is the correct one for your choosen hashing algorithm. For the default sha256 it should be 64, for sha512 is should be 128, for md5 is should be 32 and for sha1 it should be 40 etc.

I guess you could overload the __get() and __set() methods if you really want to change the table fields. Or you could create a database view but that could give problems with insert and update queries. Or try out Wouter's A1 module which does let you change the column names it uses.

Darsstar
  • 1,885
  • 1
  • 14
  • 14
  • I don't know what you are telling, I just asked about table name and fieldname or table structure that I should have for using Kohana Auth module. Or where I can change it to my own table and fields. – Hafiz Nov 08 '11 at 00:14
  • I recall reading "So please tell if some one is already using it. And if it use some default fields of some table then how can I modify it?" so the second alinea is about that. And the [ORM module](https://github.com/kohana/ORM) has two .sql files. Some people run into troubles when they change the default hash algorithm Auth uses to a longer one, so I wrote a bit about that too. – Darsstar Nov 08 '11 at 07:14