Sha256: 6cd81480f39e07f62ab97ed8541ad21984255ae3d835dd38832db810eb4641fd

Contents?: true

Size: 1.64 KB

Versions: 35

Compression:

Stored size: 1.64 KB

Contents

= Use a non-email login

Rodauth's by default uses email addresses for identifying users, since that is
the most common form of identifier currently. In some cases, you might want
to allow logging in via alternative identifiers, such as a username.  In this
case, it is best to choose a different column name for the login, such as
+:username+.  Among other things, this also makes it so that the login field
does not expect an email address to be provided.

  plugin :rodauth do
    enable :login, :logout
    login_column :username
  end

Note that Rodauth features that require sending email need an email address, and
that defaults to the value of the login column.  If you have both a username and
an email for an account, you can have the login column be the user, and use the
value of the email colummn for the email address.

  plugin :rodauth do
    enable :login, :logout, :reset_password

    login_column :username
    email_to do
      account[:email]
    end
  end

An alternative approach would be to accept a login and automatically change it
to an email address. If you have a +username+ field on the +accounts+ table,
then you can configure Rodauth to allow entering a username instead of email
during login.  See the {Adding new registration field}[rdoc-ref:doc/guides/registration_field.rdoc]
guide for instructions on requiring add an additional field during registration.

  plugin :rodauth do
    enable :login, :logout

    account_from_login do |login|
      # handle the case when login parameter is a username
      unless login.include?("@")
        login = db[:accounts].where(username: login).get(:email)
      end

      super(login)
    end
  end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
rodauth-2.36.0 doc/guides/alternative_login.rdoc
rodauth-2.34.0 doc/guides/alternative_login.rdoc
rodauth-2.33.0 doc/guides/alternative_login.rdoc
rodauth-2.32.0 doc/guides/alternative_login.rdoc
rodauth-2.31.0 doc/guides/alternative_login.rdoc
rodauth-2.30.0 doc/guides/alternative_login.rdoc
rodauth-2.29.0 doc/guides/alternative_login.rdoc
rodauth-2.28.0 doc/guides/alternative_login.rdoc
rodauth-2.27.0 doc/guides/alternative_login.rdoc
rodauth-2.26.1 doc/guides/alternative_login.rdoc
rodauth-2.26.0 doc/guides/alternative_login.rdoc
rodauth-2.25.0 doc/guides/alternative_login.rdoc
rodauth-2.24.0 doc/guides/alternative_login.rdoc
rodauth-2.23.0 doc/guides/alternative_login.rdoc
rodauth-2.22.0 doc/guides/alternative_login.rdoc
rodauth-2.21.0 doc/guides/alternative_login.rdoc
rodauth-2.20.0 doc/guides/alternative_login.rdoc
rodauth-2.19.0 doc/guides/alternative_login.rdoc
rodauth-2.18.0 doc/guides/alternative_login.rdoc
rodauth-2.17.0 doc/guides/alternative_login.rdoc