How to create a separate Devise authentication for certain areas?
My app has a controller whose actions need to be cut off from authenticated users behind a special password.
One way to imagine it: regular users go about their business. Once in a while, an admin needs to enter his/her password to let the regular users access an area.
I have Devise authentication set up the normal way in my app, so all my users are authenticated.
How can I now set up a separate password so all calls to a controller result in a request for a special separate password?
ruby-on-rails devise ruby-on-rails-5
add a comment |
My app has a controller whose actions need to be cut off from authenticated users behind a special password.
One way to imagine it: regular users go about their business. Once in a while, an admin needs to enter his/her password to let the regular users access an area.
I have Devise authentication set up the normal way in my app, so all my users are authenticated.
How can I now set up a separate password so all calls to a controller result in a request for a special separate password?
ruby-on-rails devise ruby-on-rails-5
Hi, I'm curious to know if my solution has worked for you.
– Abhilash Reddy
Nov 29 '18 at 3:33
add a comment |
My app has a controller whose actions need to be cut off from authenticated users behind a special password.
One way to imagine it: regular users go about their business. Once in a while, an admin needs to enter his/her password to let the regular users access an area.
I have Devise authentication set up the normal way in my app, so all my users are authenticated.
How can I now set up a separate password so all calls to a controller result in a request for a special separate password?
ruby-on-rails devise ruby-on-rails-5
My app has a controller whose actions need to be cut off from authenticated users behind a special password.
One way to imagine it: regular users go about their business. Once in a while, an admin needs to enter his/her password to let the regular users access an area.
I have Devise authentication set up the normal way in my app, so all my users are authenticated.
How can I now set up a separate password so all calls to a controller result in a request for a special separate password?
ruby-on-rails devise ruby-on-rails-5
ruby-on-rails devise ruby-on-rails-5
asked Nov 22 '18 at 2:00
sscirrussscirrus
27.7k40114206
27.7k40114206
Hi, I'm curious to know if my solution has worked for you.
– Abhilash Reddy
Nov 29 '18 at 3:33
add a comment |
Hi, I'm curious to know if my solution has worked for you.
– Abhilash Reddy
Nov 29 '18 at 3:33
Hi, I'm curious to know if my solution has worked for you.
– Abhilash Reddy
Nov 29 '18 at 3:33
Hi, I'm curious to know if my solution has worked for you.
– Abhilash Reddy
Nov 29 '18 at 3:33
add a comment |
1 Answer
1
active
oldest
votes
One way to do it is introducing a simple authentication from scratch on top of Devise's authentication
using thebcryptlibrary .
You will need a new field in your users table to store the special password digest. So, create a new migration file and the below code to it:
def change
add_column :users, :special_password, :digest
end
Add Bcrypt gem to your Gemfile:
gem 'bcrypt', '~> 3.1', '>= 3.1.12'
To your user model add the below line:
has_secure_special_password
Now in your special password authentication controller, use the below code to authenticate current_user with the special_password
if current_user.authenticate(params[:user][:special_password])
session[:special_user_id] = current_user.id
end
Now in whichever controller actions you want to authenticate the user with the special password, Create a before_action filter and try to find the user by session[:special_user_id] and if user not found you may ask them to enter the special_password
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422890%2fhow-to-create-a-separate-devise-authentication-for-certain-areas%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
One way to do it is introducing a simple authentication from scratch on top of Devise's authentication
using thebcryptlibrary .
You will need a new field in your users table to store the special password digest. So, create a new migration file and the below code to it:
def change
add_column :users, :special_password, :digest
end
Add Bcrypt gem to your Gemfile:
gem 'bcrypt', '~> 3.1', '>= 3.1.12'
To your user model add the below line:
has_secure_special_password
Now in your special password authentication controller, use the below code to authenticate current_user with the special_password
if current_user.authenticate(params[:user][:special_password])
session[:special_user_id] = current_user.id
end
Now in whichever controller actions you want to authenticate the user with the special password, Create a before_action filter and try to find the user by session[:special_user_id] and if user not found you may ask them to enter the special_password
add a comment |
One way to do it is introducing a simple authentication from scratch on top of Devise's authentication
using thebcryptlibrary .
You will need a new field in your users table to store the special password digest. So, create a new migration file and the below code to it:
def change
add_column :users, :special_password, :digest
end
Add Bcrypt gem to your Gemfile:
gem 'bcrypt', '~> 3.1', '>= 3.1.12'
To your user model add the below line:
has_secure_special_password
Now in your special password authentication controller, use the below code to authenticate current_user with the special_password
if current_user.authenticate(params[:user][:special_password])
session[:special_user_id] = current_user.id
end
Now in whichever controller actions you want to authenticate the user with the special password, Create a before_action filter and try to find the user by session[:special_user_id] and if user not found you may ask them to enter the special_password
add a comment |
One way to do it is introducing a simple authentication from scratch on top of Devise's authentication
using thebcryptlibrary .
You will need a new field in your users table to store the special password digest. So, create a new migration file and the below code to it:
def change
add_column :users, :special_password, :digest
end
Add Bcrypt gem to your Gemfile:
gem 'bcrypt', '~> 3.1', '>= 3.1.12'
To your user model add the below line:
has_secure_special_password
Now in your special password authentication controller, use the below code to authenticate current_user with the special_password
if current_user.authenticate(params[:user][:special_password])
session[:special_user_id] = current_user.id
end
Now in whichever controller actions you want to authenticate the user with the special password, Create a before_action filter and try to find the user by session[:special_user_id] and if user not found you may ask them to enter the special_password
One way to do it is introducing a simple authentication from scratch on top of Devise's authentication
using thebcryptlibrary .
You will need a new field in your users table to store the special password digest. So, create a new migration file and the below code to it:
def change
add_column :users, :special_password, :digest
end
Add Bcrypt gem to your Gemfile:
gem 'bcrypt', '~> 3.1', '>= 3.1.12'
To your user model add the below line:
has_secure_special_password
Now in your special password authentication controller, use the below code to authenticate current_user with the special_password
if current_user.authenticate(params[:user][:special_password])
session[:special_user_id] = current_user.id
end
Now in whichever controller actions you want to authenticate the user with the special password, Create a before_action filter and try to find the user by session[:special_user_id] and if user not found you may ask them to enter the special_password
edited Nov 22 '18 at 3:56
answered Nov 22 '18 at 3:23
Abhilash ReddyAbhilash Reddy
1,1401618
1,1401618
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422890%2fhow-to-create-a-separate-devise-authentication-for-certain-areas%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown

Hi, I'm curious to know if my solution has worked for you.
– Abhilash Reddy
Nov 29 '18 at 3:33