Question

I want to use numbers as username in Kohana Auth. For example, username 100001? While adding new user Kohana returns me error: ORM_Validation_Exception [ 0 ]: Failed to validate array Is is possible to user numbers as username in Kohana?

No correct solution

OTHER TIPS

EDIT: This answer looks simpler and better than mine, but try to understand it at all.


You need to extend User Model, I'll help you using auth with the ORM driver.

Steps to extend User Model:

  1. If you didn't yet, configure Auth module to use orm and create a database table with the fields you want. Here is a good example of how to doing it (It's an old tutorial using ko3.1 but you can still learn from it). PS.: you can have any columns at the 'users' table and you don't need to have the 'username' column if you do not want.

  2. Open and read carefully this file: MODULES/orm/classes/model/auth/user.php (It's self documented and I hope you understand it. If not, stop reading this answer here and read the kohana docs. Some shortcuts: Auth - Kohana User Guide, Auth (orm) methods, addons:auth

  3. Copy the file (don't edit the original) to APPPATH/classes/model/auth/user.php and edit it how you want. Some functions that you may like to edit are: rules, filters and unique_key (<- useful). Be creative, you also can add custom functions.

  4. Test and change whatever else needed.

 


You can change the login method to works as you like. You can set login by e-mail, make a custom validation method or parse values before saving in the database (see public function filters()). This is helpful for whatever you try to do with auth module using ORM... But... if you really don't want to use ORM, you can build your own driver, learn how.

I made this some time ago in kohana 3.2 but I think you won't get problems with 3.3. If you still have questions, this question on kohana forum may help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top