rpassword-protectionbookdownblogdown

Adding a password to one page of a blogdown site


Is it possible to password protect one page of a website made using R blogdown, published using the free version of Netlify?

If not, it it possible to host a password protected RMD file on a blogdown website? I tried using the encryptedRmd package but I don't think it's meant for this..


Solution

  • I was able to add basic password protection for one page on my website using Brent Scott's pagecryptr package, which is a R-wrapper for PageCrypt. The set up is very simple thanks to the R package.

    1. Create the password protected version of the RMD file, knit it to HTML, and save it somewhere (literally anywhere, but I put it on my private repository on GitHub). We'll call this file password.html.
    2. Name the page you want to password protect in your TOML file. Mine looks like this:
    [[menu.main]]
        name = "Portfolio"
        url = "/Portfolio/"
    

    Note that you do not need to create a RMD or HTML file for this page because we'll be using pagecryptr to create it.

    1. Install pagecryptr
    install.packages("drat")
    drat::addRepo("brentscott93")
    install.packages("pagecryptr")
    library(pagecryptr)
    
    1. In a different R script, run pagecryptr to password protect the file:
    if(interactive()){
     file <- "~/password.html"
     pagecryptr(file, "password123", out_file = "~/content/Portfolio.html")
    }
    

    Notice how pagecryptr is taking the file we want to password protect (password.html) and writing HTML for it that corresponds to the page we created in our TOML (Portfolio.html). The second argument contains the password you want to use for the website (in this example, it's password123).

    Commit Portfolio.html to GitHub and you will have a password protected page on your website!