Wednesday, 11 February 2015

Snippet: Password Generator.

Password Generator

This code will generate password, hide and unhide it.

<html>
<head>
<style>
input[type=checkbox]
{
  -ms-transform: scale(1.2); 
  -moz-transform: scale(1.2); 
  -webkit-transform: scale(1.2); 
  -o-transform: scale(1.2); 
  padding: 5px;
}

</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
function change_char(){
var pass = document.getElementById("pw");
var checkbox = document.getElementById("cb");
if(pass.type == "password"){
pass.type = "text";
checkbox.checked = true;
}else{
pass.type = "password";
checkbox.checked = false;
}
}

$(document).ready(function(){
$('#generate_pass').click(function(){
$.post('generate.php', function(result){
$('#pw').val(result);
});
});
});
</script>
<title>Show Password Character</title>
</head>
<body>
Password:</br>
<input type="password" name="password" id="pw"> 
<input type="button" name="generate_pass" id="generate_pass" value="Generate Password"></br>
<input type="checkbox" name="checkbox" id="cb" onClick="change_char();"> Show Characters
</body>
</html>

Code Generator

<?php
$characters='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$pass_characters = str_split($characters);
$pass_length = "8";
$password='';

for($i=0;$i<$pass_length;$i++){
$password.=$pass_characters[rand(0,count($pass_characters)-1)];
}
echo $password;
?>


Enjoy the Code!

Snippet: Check All


Hello people this is a simple snippet written in javascript. The code is check all and clear all checkbox.
Below is the code:

<html>
<head>
<script type="text/javascript">
function checkAll(checkEm) {
    var cbs = document.getElementsByTagName('input');
    for (var i = 0; i < cbs.length; i++) {
        if (cbs[i].type == 'checkbox') {
            if (cbs[i].name == 'menu[]') {
                cbs[i].checked = checkEm;
            }
        }
    }
}
</script>
</head>
<body>
<form action="" method="post">
<input type="checkbox" name="menu[]" value="menu1" style="width: 16px;">Menu 1<br>
<input type="checkbox" name="menu[]" value="menu2" style="width: 16px;">Menu 2<br>
<input type="checkbox" name="menu[]" value="menu3" style="width: 16px;">Menu 3<br>
<input type="checkbox" name="menu[]" value="menu4" style="width: 16px;">Menu 4<br>
<input type="button" class="my_form-check-button" onClick="checkAll(true);" value="Check All"/>
<input type="button" class="my_form-check-button" onClick="checkAll(false);" value="Clear All"/>
</form>
</body>
</html>

Hope you learn from this simple code.