Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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