This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/application/classes/lnapp/pwgen.php
2012-07-12 21:28:42 +10:00

37 lines
1.2 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for providing password from a password genarator
*
* @package lnApp
* @subpackage PWGen
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_PWgen {
public static function get($pwonly=TRUE) {
if (! Kohana::Config('pwgen.host') OR ! Kohana::Config('pwgen.port'))
throw new Kohana_Exception('No configuration for host or port (:host/:port)',array(':host'=>Kohana::Config('pwgen.host'),':port'=>Kohana::Config('pwgen.port')));
$ps = socket_create(AF_INET,SOCK_STREAM,0);
if (! socket_connect($ps,Kohana::Config('pwgen.host'),Kohana::Config('pwgen.port')))
throw new Kohana_Exception('Unable to connect to password server');
// echo "Reading response:\n\n";
$pw = '';
while ($out = socket_read($ps,64))
$pw .= rtrim($out);
// echo "Closing socket...";
socket_close ($ps);
list($passwd,$passwdSay) = explode(' ',$pw);
// print " Password [$passwd] ($passwdSay) [$pw] ".md5($passwd)."<BR>";
return $pwonly ? $passwd : array('pw'=>$passwd,'say'=>$passwdSay);
}
}
?>