Skip to content

Instantly share code, notes, and snippets.

@BackSpaceTech
Last active September 11, 2016 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BackSpaceTech/41ed0973b96cf1360dc788ad5219a7b9 to your computer and use it in GitHub Desktop.
Save BackSpaceTech/41ed0973b96cf1360dc788ad5219a7b9 to your computer and use it in GitHub Desktop.
Shared Responsibility 2 - Using Dynamic CSS Selectors to stop the bots.
var express = require('express')
var app = express();
app.set('port', (process.env.PORT ||8080));
app.use(express.static(__dirname + '/public'));
app.get('/', function(request, response) {
response.send(dynamicCSS())
})
var loginElements = {
username: '',
password: ''
}
function dynamicCSS(){
var username, password
x = ''
if ((Math.random()*2) > 1)
x += '<style>.btnSubmit,.password,.username{position:absolute;left:10}.username{top:50px}.password{top:80px}.btnSubmit{top:110px}</style>'
else
x += '<style>.btnSubmit,.password,.username{position:absolute;left:10}.username{top:80px}.password{top:110px}.btnSubmit{top:140px}</style>'
x += '<form>'
x += '<h1>Please Login</h1>'
y = Math.floor((Math.random()*5)) + 2
for (var a=0; a<y; ++a){
username = randonString()
password = randonString()
x += '<input type="text" class="username" id="' + username + '" name="' + username + '" placeholder="Enter Username"></input>'
x += '<input type="password" class="password" id="' + password + '" name="' + password + '" placeholder="Enter Password"></input>'
loginElements.username = username
loginElements.password = password
}
for (var a=0; a<y; ++a){
username = randonString()
password = randonString()
x += '<input type="text" class="username" id="' + username + '" name="' + username + '" placeholder="Enter Username"></input>'
x += '<input type="password" class="password" id="' + password + '" name="' + password + '" placeholder="Enter Password"></input>'
document.getElementById(username).style.visibility = "hidden";
document.getElementById(password).style.visibility = "hidden";
}
x += '<button class="btnSubmit" type="submit">Log in</button>'
x += '</form>'
return x
}
function randonString(){
chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('')
chars.sort(function() {
return 0.5 - Math.random()
})
return chars.splice(0, 8).toString().replace(/,/g, '')
}
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment