Skip to content
Snippets Groups Projects
Commit 521f1c8b authored by Will Billingsley's avatar Will Billingsley
Browse files

Initial example for students to build off

parents
No related branches found
No related tags found
No related merge requests found
target
logs
.idea/
package controllers;
import model.BCryptExample;
import play.mvc.Controller;
import play.mvc.Result;
public class Application extends Controller {
public static Result encrypt(String pw) {
return ok(views.html.application.encrypted.render(BCryptExample.encrypt(pw)));
}
public static Result matches(String pw) {
return ok(views.html.application.matches.render(BCryptExample.matchesLastEncrypted(pw)));
}
public static Result index() {
return ok(views.html.application.index.render());
}
}
package model;
import org.mindrot.jbcrypt.BCrypt;
/**
* A little demo code to show how BCrypt is used to hash passwords
*/
public class BCryptExample {
// Eek, not threadsafe.
static String last;
public static String encrypt(String s) {
last = BCrypt.hashpw(s, BCrypt.gensalt());
return last;
}
public static boolean matchesLastEncrypted(String pw) {
return BCrypt.checkpw(pw, last);
}
}
@(hash: String)
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>Here's that encrypted with a new salt:</h1>
<p>@hash</p>
<h2>Check a password matches the last one</h2>
<form action="matches">
<input type="password" name="pw" />
<button type="submit">Check</button>
</form>
</body>
</html>
\ No newline at end of file
@()
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>Encrypt a password:</h1>
<form action="encrypt">
<input type="password" name="pw" />
<button type="submit">Submit</button>
</form>
</body>
</html>
\ No newline at end of file
@(matches: Boolean)
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
@if(matches) {
<h1>Yes, it matched!</h1>
} else {
<h2>Noo, that wasn't the password</h2>
}
<h2>Check a password matches the last one</h2>
<form action="matches">
<input type="password" name="pw" />
<button type="submit">Check</button>
</form>
</body>
</html>
\ No newline at end of file
name := "chirper"
version := "1.0"
scalaVersion := "2.11.6"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
libraryDependencies ++= Seq(
"org.mindrot" % "jbcrypt" % "0.3m"
)
# This is the main configuration file for the application.
# ~~~~~
# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
#
# This must be changed for production, but we recommend not changing it in this file.
#
# See http://www.playframework.com/documentation/latest/ApplicationSecret for more details.
play.crypto.secret = "changeme"
# The application languages
# ~~~~~
play.i18n.langs = [ "en" ]
# Router
# ~~~~~
# Define the Router object to use for this application.
# This router will be looked up first when the application is starting up,
# so make sure this is the entry point.
# Furthermore, it's assumed your route file is named properly.
# So for an application router like `my.application.Router`,
# you may need to define a router file `conf/my.application.routes`.
# Default to Routes in the root package (and conf/routes)
# play.http.router = my.application.Routes
# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
# db.default.driver=org.h2.Driver
# db.default.url="jdbc:h2:mem:play"
# db.default.username=sa
# db.default.password=""
# Evolutions
# ~~~~~
# You can disable evolutions if needed
# play.evolutions.enabled=false
# You can disable evolutions for a specific datasource if necessary
# play.evolutions.db.default.enabled=false
\ No newline at end of file
<!-- Based on the version from typesafe activator -->
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel - %logger - %message%n%xException</pattern>
</encoder>
</appender>
<!--
The logger name is typically the Java/Scala package name.
This configures the log level to log at for a package and its children packages.
-->
<logger name="play" level="INFO" />
<logger name="application" level="DEBUG" />
<root level="ERROR">
<appender-ref ref="STDOUT" />
</root>
</configuration>
\ No newline at end of file
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index()
GET /encrypt controllers.Application.encrypt(pw)
GET /matches controllers.Application.matches(pw)
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
\ No newline at end of file
sbt.version=0.13.8
// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment