Sha256: 9a48c5fdccf4ac18075fc4fd5146ca0fdae14059434ed0eb6f3143c3f12c74e9

Contents?: true

Size: 1.1 KB

Versions: 35

Compression:

Stored size: 1.1 KB

Contents

= Create an account record programmatically

In some scenarios you might want to create an account records programmatically,
for example in your tests.

If you're storing passwords in a separate table, you can create an account
records as follows:

  account_id = DB[:accounts].insert(
    email:     "name@example.com",
    status_id: 2, # verified
  )

  DB[:account_password_hashes].insert(
    id:            account_id,
    password_hash: BCrypt::Password.create("secret").to_s,
  )

If the password is stored in a column in the accounts table:

  account_id = DB[:accounts].insert(
    email:         "name@example.com",
    password_hash: BCrypt::Password.create("secret").to_s,
    status_id:     2, # verified
  )

If you are creating accounts in your tests, you probably want to use
the +:cost+ option, otherwise you will have very slow tests:

  account_id = DB[:accounts].insert(
    email:     "name@example.com",
    status_id: 2, # verified
  )

  DB[:account_password_hashes].insert(
    id:            account_id,
    password_hash: BCrypt::Password.create("secret", cost: BCrypt::Engine::MIN_COST).to_s,
  )

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
rodauth-2.16.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.15.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.14.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.13.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.12.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.11.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.10.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.9.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.8.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.7.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.6.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.5.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.4.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.3.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.2.0 doc/guides/create_account_programmatically.rdoc