Skip to content

Commit

Permalink
add shiny app
Browse files Browse the repository at this point in the history
  • Loading branch information
bbartholdy committed Jul 6, 2024
1 parent 380c091 commit c628ed5
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 2 deletions.
3 changes: 3 additions & 0 deletions R/run_app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
runRing <- function(){
shiny::runApp(system.file("shinyapp", package = "keepitsecret"))
}
3 changes: 3 additions & 0 deletions R/test_password.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#' online with no throttling;
#' and, if the password is weak, prints warning and suggestions for improvement (if `verbose = TRUE`).
#' @param pw string. Password to test against Pwned Passwords database.
#' @param verbose logical. Should the output be printed in the console? Default is `TRUE`.
#' @rdname password-testing
#' @examples
#' \dontrun{
Expand All @@ -26,6 +27,8 @@
#' }
#' @export
is_it_secret <- function(pw, verbose = T){
# test internet connection
if(!curl::has_internet()) stop("You don't seem to be connected to the internet.")
pw_sha1 <- openssl::sha1(pw)
hash_prefix <- stringr::str_to_upper(stringr::str_extract(pw_sha1, "^\\w{5}"))
hash_suffix <- stringr::str_to_upper(stringr::str_remove(pw_sha1, "\\w{5}"))
Expand Down
10 changes: 10 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ will contain words straight out of the Lord of the Rings novel!
It was heavily inspired by [this xkcd comic](https://xkcd.com/936/) and
[this Phoenix Nap blog post](https://phoenixnap.com/blog/strong-great-password-ideas).

A Shiny app is available here: https://websaur.shinyapps.io/keepitsecret/

## Installation

You can install the development version of keepitsecret like so:
Expand Down Expand Up @@ -71,3 +73,11 @@ is_it_safe("password1234")

![yes, yes, this part is only in the movie...](https://i.imgflip.com/8gwn0y.jpg)

## Shiny app

You can also use the Shiny app instead of the console.

```{r shiny}
#| eval: false
runRing() # to rule them all
```
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ It was heavily inspired by [this xkcd comic](https://xkcd.com/936/) and
[this Phoenix Nap blog
post](https://phoenixnap.com/blog/strong-great-password-ideas).

A Shiny app is available here:
<https://websaur.shinyapps.io/keepitsecret/>

## Installation

You can install the development version of keepitsecret like so:
Expand All @@ -33,7 +36,7 @@ To generate a password.
library(keepitsecret)
pw <- keep_it_safe()
pw
#> [1] "Folco-Imladris-objection-bread"
#> [1] "saluting-death’s-uniquely-enormous"
```

You can also test whether a password has been part of a data breach (is
Expand Down Expand Up @@ -78,3 +81,11 @@ alt="yes, yes, this part is only in the movie…" />
<figcaption aria-hidden="true">yes, yes, this part is only in the
movie…</figcaption>
</figure>

## Shiny app

You can also use the Shiny app instead of the console.

``` r
runRing() # to rule them all
```
10 changes: 10 additions & 0 deletions inst/shinyapp/rsconnect/shinyapps.io/websaur/keepitsecret.dcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: keepitsecret
title:
username: websaur
account: websaur
server: shinyapps.io
hostUrl: https://api.shinyapps.io/v1
appId: 12282208
bundleId: 8831578
url: https://websaur.shinyapps.io/keepitsecret/
version: 1
41 changes: 41 additions & 0 deletions inst/shinyapp/server.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
library(shiny)
library(keepitsecret)

server <- function(input, output, session) {

values <- reactiveValues()

gen_pw <- eventReactive(input$generate, {
if(input$method == "word"){
values$pw <- keep_it_safe(input$method, input$n, input$cap, input$sep, min_size = input$min_size[1], max_size = input$min_size[2])
} else if(input$method == "sentence"){
values$pw <- keep_it_safe(input$method, input$n)
} else if(input$method == "phrase"){
values$pw <- keep_it_safe(input$method, input$n, input$sep)
}

print(values$pw)
})

safe <- eventReactive(input$generate, {
values$safe <- is_it_safe(values$pw, verbose = F)
print(values$safe$crack_times_display$online_no_throttling_10_per_second)
})

secret <- eventReactive(input$generate, {
values$secret <- is_it_secret(values$pw)
print(values$secret)
})

output$password <- renderText({
gen_pw()
})

output$password_strength <- renderText({
paste("Time to crack:", safe())
})

output$password_secrecy <- renderText({
paste("Appearances in data breaches:", secret())
})
}
65 changes: 65 additions & 0 deletions inst/shinyapp/ui.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
library(shiny)
library(bslib)

ui <- page_sidebar(
theme = bs_theme(bootswatch = "darkly"),
sidebar = sidebar(
img(src = "hexsticker.png", width = 150, style = "margin-left: auto; margin-right: auto;"),
# Select variable for y-axis
selectInput(
inputId = "method",
label = "Method",
choices = c(
"Random words" = "word",
"Sentence method" = "sentence",
"Phrase method" = "phrase"
),
selected = "word"
),
conditionalPanel(
condition = "input.method == 'word'",
sliderInput("n", "How many words?",
min = 1, max = 10, value = 4
),
sliderInput("min_size", "Word size",
min = 2, max = 10, value = c(4, 6),
),
radioButtons("cap", "Capitalisation",
choices = c("original", "none", "title"),
selected = "original"
),
textInput("sep", "Separator",
value = "-",
placeholder = "e.g. a space, ';' or '-'"
)
),
conditionalPanel(
condition = "input.method == 'sentence'",
sliderInput("digit_count", "How many words?",
min = 1, max = 10, value = 6
),
textInput("sep", "Separator",
value = "-",
placeholder = "e.g. a space, ';' or '-'"
)
),
conditionalPanel(
condition = "input.method == 'phrase'",
sliderInput("digit_count", "How many words?",
min = 1, max = 10, value = 4
)
),
actionButton("generate", "Generate password"),
),

# Output: Generate password
card(
h3("Your new password"),
h4(textOutput(outputId = "password"))
),
card(
h3("Password strength"),
h4(textOutput(outputId = "password_strength")),
h4(textOutput(outputId = "password_secrecy"))
)
)
Binary file added inst/shinyapp/www/hexsticker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion man/password-testing.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c628ed5

Please sign in to comment.