How to add simple http authentication in Ruby on Rails

How to add simple http authentication in Ruby on Rails

/ #Ruby on Rails


Sometimes you don't need a fancy authentication for your website, here's how to can implement that.

Instead of implementing something like Devise, or your own authentication, you can just use simple http authentication from Ruby on Rails.

Maybe you just need to hide a simple admin section, not ready to show the website to the world, etc. When that's the case, this simple solution is really great.

class Admin::PostsController < ApplicationController
  http_basic_authenticate_with name: "codewithstein", password: "rubyonrails"

  def index
    @posts = Post.order(created_at: :desc)
  end
end

So with this one line, you will now need a username and password to access this controller. Note that saving passwords like this in clear text is not so called best practice, so keep that in mind.

Comments

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

-1 OR 2+443-443-1=0+0+0+1 --

EFSArCBy | Jul 02, 26 07:29

-1 OR 2+583-583-1=0+0+0+1

EFSArCBy | Jul 02, 26 07:29

-1' OR 2+900-900-1=0+0+0+1 --

EFSArCBy | Jul 02, 26 07:29

-1' OR 2+998-998-1=0+0+0+1 or 'LsKxz10o'='

EFSArCBy | Jul 02, 26 07:29

-1" OR 2+646-646-1=0+0+0+1 --

EFSArCBy | Jul 02, 26 07:29

555*if(now()=sysdate(),sleep(15),0)

EFSArCBy | Jul 02, 26 07:29

5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z

EFSArCBy | Jul 02, 26 07:29

5550"XOR(555*if(now()=sysdate(),sleep(15),0))XOR"Z

EFSArCBy | Jul 02, 26 07:29

(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

EFSArCBy | Jul 02, 26 07:29

555-1; waitfor delay '0:0:15' --

EFSArCBy | Jul 02, 26 07:29

555-1); waitfor delay '0:0:15' --

EFSArCBy | Jul 02, 26 07:29

555-1 waitfor delay '0:0:15' --

EFSArCBy | Jul 02, 26 07:29

555Dr7Gb1lk'; waitfor delay '0:0:15' --

EFSArCBy | Jul 02, 26 07:29

555-1 OR 156=(SELECT 156 FROM PG_SLEEP(15))--

EFSArCBy | Jul 02, 26 07:29

555-1) OR 921=(SELECT 921 FROM PG_SLEEP(15))--

EFSArCBy | Jul 02, 26 07:29

555-1)) OR 629=(SELECT 629 FROM PG_SLEEP(15))--

EFSArCBy | Jul 02, 26 07:29

555k1fTXApn' OR 230=(SELECT 230 FROM PG_SLEEP(15))--

EFSArCBy | Jul 02, 26 07:29

555VcvzLaRY') OR 620=(SELECT 620 FROM PG_SLEEP(15))--

EFSArCBy | Jul 02, 26 07:29

555UhWj1W3E')) OR 717=(SELECT 717 FROM PG_SLEEP(15))--

EFSArCBy | Jul 02, 26 07:29

555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

EFSArCBy | Jul 02, 26 07:29

555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555'"

EFSArCBy | Jul 02, 26 07:29

@@2mY5l

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

-1 OR 2+947-947-1=0+0+0+1 -- | Jul 02, 26 07:29

555

-1 OR 2+76-76-1=0+0+0+1 | Jul 02, 26 07:29

555

-1' OR 2+736-736-1=0+0+0+1 -- | Jul 02, 26 07:29

555

-1' OR 2+160-160-1=0+0+0+1 or 'TNyl1Hys'=' | Jul 02, 26 07:29

555

-1" OR 2+255-255-1=0+0+0+1 -- | Jul 02, 26 07:29

555

if(now()=sysdate(),sleep(15),0) | Jul 02, 26 07:29

555

EFSArCBy0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z | Jul 02, 26 07:29

555

EFSArCBy0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z | Jul 02, 26 07:29

555

EFSArCBy-1 waitfor delay '0:0:15' -- | Jul 02, 26 07:29

555

EFSArCByFPCComuf'; waitfor delay '0:0:15' -- | Jul 02, 26 07:29

555

EFSArCByA7zwywwg' OR 289=(SELECT 289 FROM PG_SLEEP(15))-- | Jul 02, 26 07:29

555

EFSArCByQl2ECsSI') OR 292=(SELECT 292 FROM PG_SLEEP(15))-- | Jul 02, 26 07:29

555

EFSArCByQTATPE3w')) OR 535=(SELECT 535 FROM PG_SLEEP(15))-- | Jul 02, 26 07:29

555

EFSArCBy'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||' | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy'" | Jul 02, 26 07:29

555

@@0D1sd | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 02, 26 07:29

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

-1 OR 2+257-257-1=0+0+0+1 --

EFSArCBy | Jul 20, 26 08:32

-1 OR 2+201-201-1=0+0+0+1

EFSArCBy | Jul 20, 26 08:32

-1' OR 2+548-548-1=0+0+0+1 --

EFSArCBy | Jul 20, 26 08:32

-1' OR 2+121-121-1=0+0+0+1 or 'qh2bJxbN'='

EFSArCBy | Jul 20, 26 08:32

-1" OR 2+969-969-1=0+0+0+1 --

EFSArCBy | Jul 20, 26 08:32

555*if(now()=sysdate(),sleep(15),0)

EFSArCBy | Jul 20, 26 08:32

5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z

EFSArCBy | Jul 20, 26 08:32

5550"XOR(555*if(now()=sysdate(),sleep(15),0))XOR"Z

EFSArCBy | Jul 20, 26 08:32

(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

EFSArCBy | Jul 20, 26 08:32

555-1; waitfor delay '0:0:15' --

EFSArCBy | Jul 20, 26 08:32

555-1); waitfor delay '0:0:15' --

EFSArCBy | Jul 20, 26 08:32

555-1 waitfor delay '0:0:15' --

EFSArCBy | Jul 20, 26 08:32

555sFqGKAim'; waitfor delay '0:0:15' --

EFSArCBy | Jul 20, 26 08:32

555-1 OR 414=(SELECT 414 FROM PG_SLEEP(15))--

EFSArCBy | Jul 20, 26 08:32

555-1) OR 217=(SELECT 217 FROM PG_SLEEP(15))--

EFSArCBy | Jul 20, 26 08:32

555-1)) OR 272=(SELECT 272 FROM PG_SLEEP(15))--

EFSArCBy | Jul 20, 26 08:32

555N268Eyw6' OR 42=(SELECT 42 FROM PG_SLEEP(15))--

EFSArCBy | Jul 20, 26 08:32

555oNoFY7yz') OR 818=(SELECT 818 FROM PG_SLEEP(15))--

EFSArCBy | Jul 20, 26 08:32

5552H97Ygsi')) OR 784=(SELECT 784 FROM PG_SLEEP(15))--

EFSArCBy | Jul 20, 26 08:32

555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

EFSArCBy | Jul 20, 26 08:32

555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555'"

EFSArCBy | Jul 20, 26 08:32

@@qk7JR

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:32

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

-1 OR 2+210-210-1=0+0+0+1 -- | Jul 20, 26 08:33

555

-1 OR 2+157-157-1=0+0+0+1 | Jul 20, 26 08:33

555

-1' OR 2+63-63-1=0+0+0+1 -- | Jul 20, 26 08:33

555

-1' OR 2+867-867-1=0+0+0+1 or 'OfA6Fnzp'=' | Jul 20, 26 08:33

555

-1" OR 2+457-457-1=0+0+0+1 -- | Jul 20, 26 08:33

555

if(now()=sysdate(),sleep(15),0) | Jul 20, 26 08:33

555

EFSArCBy0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z | Jul 20, 26 08:33

555

EFSArCBy0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z | Jul 20, 26 08:33

555

EFSArCBy-1 waitfor delay '0:0:15' -- | Jul 20, 26 08:33

555

EFSArCByiGnvVFzV'; waitfor delay '0:0:15' -- | Jul 20, 26 08:33

555

EFSArCByyRQ2NeR8' OR 96=(SELECT 96 FROM PG_SLEEP(15))-- | Jul 20, 26 08:33

555

EFSArCByOBrGQOiK') OR 750=(SELECT 750 FROM PG_SLEEP(15))-- | Jul 20, 26 08:33

555

EFSArCByY9t4iFIh')) OR 671=(SELECT 671 FROM PG_SLEEP(15))-- | Jul 20, 26 08:33

555

EFSArCBy'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||' | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy'" | Jul 20, 26 08:33

555

@@zsgzb | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 20, 26 08:33

555

EFSArCBy | Jul 23, 26 11:21

555

EFSArCBy | Jul 23, 26 11:21

555

EFSArCBy | Jul 23, 26 11:21

555

EFSArCBy | Jul 23, 26 11:21

-1 OR 2+12-12-1=0+0+0+1 --

EFSArCBy | Jul 23, 26 11:21

-1 OR 2+85-85-1=0+0+0+1

EFSArCBy | Jul 23, 26 11:21

-1' OR 2+505-505-1=0+0+0+1 --

EFSArCBy | Jul 23, 26 11:21

-1' OR 2+503-503-1=0+0+0+1 or 'Y9LFuduZ'='

EFSArCBy | Jul 23, 26 11:21

-1" OR 2+347-347-1=0+0+0+1 --

EFSArCBy | Jul 23, 26 11:21

555*if(now()=sysdate(),sleep(15),0)

EFSArCBy | Jul 23, 26 11:22

5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z

EFSArCBy | Jul 23, 26 11:22

5550"XOR(555*if(now()=sysdate(),sleep(15),0))XOR"Z

EFSArCBy | Jul 23, 26 11:22

(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

EFSArCBy | Jul 23, 26 11:22

555-1; waitfor delay '0:0:15' --

EFSArCBy | Jul 23, 26 11:22

555-1); waitfor delay '0:0:15' --

EFSArCBy | Jul 23, 26 11:22

555-1 waitfor delay '0:0:15' --

EFSArCBy | Jul 23, 26 11:22

555wAunz30O'; waitfor delay '0:0:15' --

EFSArCBy | Jul 23, 26 11:22

555-1 OR 645=(SELECT 645 FROM PG_SLEEP(15))--

EFSArCBy | Jul 23, 26 11:22

555-1) OR 160=(SELECT 160 FROM PG_SLEEP(15))--

EFSArCBy | Jul 23, 26 11:22

555-1)) OR 617=(SELECT 617 FROM PG_SLEEP(15))--

EFSArCBy | Jul 23, 26 11:22

555H0hQBRp6' OR 293=(SELECT 293 FROM PG_SLEEP(15))--

EFSArCBy | Jul 23, 26 11:22

555SFqBHYhg') OR 98=(SELECT 98 FROM PG_SLEEP(15))--

EFSArCBy | Jul 23, 26 11:22

5551yaGmNVU')) OR 792=(SELECT 792 FROM PG_SLEEP(15))--

EFSArCBy | Jul 23, 26 11:22

555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

EFSArCBy | Jul 23, 26 11:22

555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555'"

EFSArCBy | Jul 23, 26 11:22

@@uw1jV

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

-1 OR 2+780-780-1=0+0+0+1 -- | Jul 23, 26 11:22

555

-1 OR 2+89-89-1=0+0+0+1 | Jul 23, 26 11:22

555

-1' OR 2+403-403-1=0+0+0+1 -- | Jul 23, 26 11:22

555

-1' OR 2+645-645-1=0+0+0+1 or 'jpkjcfIA'=' | Jul 23, 26 11:22

555

-1" OR 2+405-405-1=0+0+0+1 -- | Jul 23, 26 11:22

555

if(now()=sysdate(),sleep(15),0) | Jul 23, 26 11:22

555

EFSArCBy0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z | Jul 23, 26 11:22

555

EFSArCBy0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z | Jul 23, 26 11:22

555

EFSArCBy-1 waitfor delay '0:0:15' -- | Jul 23, 26 11:22

555

EFSArCBymuPx4PHN'; waitfor delay '0:0:15' -- | Jul 23, 26 11:22

555

EFSArCBypqPFrDvo' OR 181=(SELECT 181 FROM PG_SLEEP(15))-- | Jul 23, 26 11:22

555

EFSArCBycK7E6boB') OR 283=(SELECT 283 FROM PG_SLEEP(15))-- | Jul 23, 26 11:22

555

EFSArCByaH1HFtII')) OR 557=(SELECT 557 FROM PG_SLEEP(15))-- | Jul 23, 26 11:22

555

EFSArCBy'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||' | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy'" | Jul 23, 26 11:22

555

@@qGQer | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

EFSArCBy | Jul 23, 26 11:22

555

Add comment

Info

Please log in to comment!

Newsletter

Subscribe to my weekly newsletter. One time per week I will send you a short summary of the tutorials I have posted in the past week.