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.36.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.34.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.33.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.32.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.31.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.30.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.29.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.28.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.27.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.26.1 doc/guides/create_account_programmatically.rdoc
rodauth-2.26.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.25.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.24.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.23.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.22.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.21.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.20.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.19.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.18.0 doc/guides/create_account_programmatically.rdoc
rodauth-2.17.0 doc/guides/create_account_programmatically.rdoc