import string from random import choice size = 9 ''.join([choice(string.letters + string.digits) for i in range(size)])
Tag Archive for password
Quick, Simple Password Generator
Generate a Unambiguous Random Password
function random_password($len = 7, $mixed_case = false)
{
$a = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789";
if(!$mixed_case) $a = strtolower($a)
$out = "";
for($i = 0; $i < $len; $i++)
$out .= $a[rand(0, strlen($a))];
return $out;
}
ios7crypt.rb
#!/usr/bin/env ruby
# Author:: Andrew Pennebaker
# Copyright:: Copyright 2007 Andrew Pennebaker
# License:: GPL
#
# == Synopsis
#
# ios7crypt: encrypts and decrypts passwords with Cisco IOS7 algorithm
#
# == Usage
#
# ios7crypt [OPTIONS]
#
# --help, -h:
# show help
#
# --encrypt, -e <password1> <password2> <password3> ...:
# prints out the encrypted passwords as hashes
#
# --decrypt, -d <hash1> <hash2> <hash3> ...:
# prints out the decrypted hashes as passwords
require "getoptlong"
require "rdoc/usage"
$xlat=[
0x64, 0x73, 0x66, 0x64, 0x3b, 0x6b, 0x66, 0x6f,
0x41, 0x2c, 0x2e, 0x69, 0x79, 0x65, 0x77, 0x72,
0x6b, 0x6c, 0x64, 0x4a, 0x4b, 0x44, 0x48, 0x53,
0x55, 0x42, 0x73, 0x67, 0x76, 0x63, 0x61, 0x36,
0x39, 0x38, 0x33, 0x34, 0x6e, 0x63, 0x78, 0x76,
0x39, 0x38, 0x37, 0x33, 0x32, 0x35, 0x34, 0x6b,
0x3b, 0x66, 0x67, 0x38, 0x37
]
def encrypt(password)
seed=rand(16)
password=password[0, 11]
hash=(0 .. (password.length-1)).collect { |i| $xlat[(seed+i)%$xlat.length] ^ password[i] }
return format("%02d", seed) + hash.collect { |e| format("%02x", e) }.join("")
end
def decrypt(hash)
seed=hash[0, 2].to_i
hash=hash[2, hash.length-1]
pairs=(0 .. (hash.length/2-1)).collect { |i| hash[i*2, 2].to_i(16) }
decrypted=(0 .. (pairs.length-1)).collect { |i| $xlat[(seed+i)%$xlat.length] ^ pairs[i] }
return (decrypted.collect { |e| e.chr }).join("")
end
opts=GetoptLong.new(
["--help", "-h", GetoptLong::NO_ARGUMENT],
["--encrypt", "-e", GetoptLong::NO_ARGUMENT],
["--decrypt", "-d", GetoptLong::NO_ARGUMENT]
)
mode = :help
opts.each do |option, value|
case option
when "--help"
RDoc::usage
when "--encrypt"
mode = :encrypt
when "--decrypt"
mode = :decrypt
end
end
case mode
when :help
RDoc::usage
when :encrypt
ARGV.each { |arg| puts encrypt(arg) }
when :decrypt
ARGV.each { |arg| puts decrypt(arg) }
end
wget with username and password
wget <a href="http://MYUSERNAME:MYPASSWORD@somesite.org/
" >http://MYUSERNAME:MYPASSWORD@somesite.org/
source
Category: Uncategorized |
Tags: agents, authentication, automation, Bash, batch, cygwin, download, linux, one-liners, password, wget
Cross platform secure password storage
A quicker method that also works cross-platform is to use OpenSSL (which macos includes). To encypt a list of secrets with the 256-bit AES, open the terminal and do: openssl enc -aes256 -salt -a -e -out secrets.aes You'll then be prompted twice for a password, after which you can begin typing whatever you want. When you've typed enough, hit control-d twice and the data will be encrypted and placed in a filed named "secrets.aes". To decrypt the file created above, do: openssl enc -aes256 -a -d -in secrets.aes Enter the password when asked and openssl will decrypt the file and print it in the terminal. Because openssl works the same under macos, bsd, linux, and (cygwin) Windows, files created like this can be used on any platform. A slight variation can be used to encrypt/decrypt files (rather than typed input): openssl enc -aes256 -salt -a -e -in myfile -out myfile.aes openssl enc -aes256 -salt -a -d -in myfile.aes -out myfile There are also other cyphers available, type "openssl enc help" for a list.
password protect a file not directory
<FilesMatch mitglieder.php> AuthType Basic AuthName "Mitglieder Bereich" AuthUserFile /path/.htpasswd require valid-user </FilesMatch>
htpasswd add user
/usr/sbin/htpasswd2 -b ./passwd user pass
C++ – Hello World
/*
*
* Semplice esempio di Hello World !!!
*/
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "Hello World !!!" << endl; // endl equivale ad un
return 0;
}
Gestionale per utente php con form di login, logout, upload e canc files
//admin.php page
<? session_start();
if($_SESSION['galleria']!="admin"){ ?>
<form method="post" action="function.php">
<input type="hidden" name="tipo" value="login">
User <input type="text" name="user"><br />
Password <input type="password" name="password">
<br />
<input type="submit" value="INVIA">
</form>
<? } else {?>
<form method="post" enctype="multipart/form-data" action="function.php">
<input type="hidden" name="tipo" value="upload">
<input type="file" name="documento">
<br />
<input type="submit" value="INVIA">
</form>
<? }
$cartella="photo";
$directory=opendir($cartella);
while($files=readdir($directory))
{
if ($files != "." and $files !="..")
print $files."<a href='function.php?tipo=canc&file=".$files."'>cancella</a><br>";
}
/*fine sessione file manager*/ ?>
<a href="function.php?tipo=logout">Logout</a>
//function.php page
<?
session_start(); /*va sempre in cima alla pagina per dirgli che abbiamo intenzione di utilizzare all'interno del documento delle variabili di sessione*/
$cartella="photo";
switch($_REQUEST['tipo']) {
case'login':
if(($_REQUEST['user']=="yourusername")&&($_REQUEST['password']=="yourpassword")){
/* creo una ariabile di sessione, che si chiamerà galleria:*/
$_SESSION['galleria']="admin";
}
/*se non c'è la variabile di sessione facciamo ritornare l'utente alla pagina di admin*/
header("location:admin.php");
break;
case'logout':
session_destroy();
header("location:admin.php"); /*this permits to return to previous page*/
break;
case'upload':
move_uploaded_file( $_FILES['documento']['tmp_name'],$cartella."/".$_FILES['documento']['name']);
chmod($cartella."/".$_FILES['documento']['name'],0666);
header("location:admin.php"); /*this permits to return to previous page*/
break;
case'canc':
unlink($cartella."/".$_REQUEST['file']);
header("location:admin.php"); /*this permits to return to previous page*/
break;
}
?>