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.
lnapp/classes/lnApp/PWgen.php

36 lines
1.2 KiB
PHP
Raw Normal View History

2013-04-22 05:50:28 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for providing password from a password genarator
*
* @package lnApp
2013-10-08 23:24:11 +00:00
* @category Helpers
2013-04-22 05:50:28 +00:00
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_PWgen {
public static function get($pwonly=TRUE) {
if (! Kohana::$config->load('pwgen')->host OR ! Kohana::$config->load('pwgen')->port)
throw new Kohana_Exception('No configuration for host or port (:host/:port)',array(':host'=>Kohana::$config->load('pwgen')->host,':port'=>Kohana::$config->load('pwgen')->port));
$ps = socket_create(AF_INET,SOCK_STREAM,0);
if (! socket_connect($ps,Kohana::$config->load('pwgen')->host,Kohana::$config->load('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);
}
}
?>