2

I'm trying to discover how Ruby on Rails generates the authentication_token field for users in a database. Is it random? Or is there some specific way of generating it that must be used?

The reason I ask is because I'm trying to add many users to a RoR app (GitLab) by creating the SQL queries directly, but I'm not sure what to put in that field. I do know that the length is fixed, and that the strings appear to be random.

Can I just put random strings in there? Or must they be generated specifically somehow?

For example, here's a row I'm trying to create manually: http://vpaste.net/IzwQH

You can see there a random 20 char string just after the name Alia Avallone. That's the "authentication_token" created by Ruby on Rails somehow. I'm wondering if it suffices to just put a random 20 byte/char length string there or if I have to create it specifically somehow. Do you know?

trusktr
  • 44,284
  • 53
  • 191
  • 263
  • I would recommend using the User model to generate the users instead of SQL directly. That way, you don't need to worry about how the auth token is generated and all columns that get auto-populated are taken care of for you. Also, the authentication_token depends on your individual implementation. See [Create a devise user from Ruby console](http://stackoverflow.com/questions/4316940/create-a-devise-user-from-ruby-console) for how to create a user from the console. – nbrew Nov 07 '13 at 00:41

0 Answers0