首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Codeigntier:无法加载请求的文件: Ubuntu 14.04上的helpers/phpass_helper.php

Codeigntier:无法加载请求的文件: Ubuntu 14.04上的helpers/phpass_helper.php
EN

Stack Overflow用户
提问于 2016-02-12 06:47:58
回答 1查看 21.8K关注 0票数 6

我正试图在我的基本控制器中加载Phpass助手,以便对我的密码进行哈希处理。然而,它似乎不能加载到Ubuntu 14.04上。我试着搜索,有人说可能是因为Linux是大小写敏感的,所以我把我的文件从Phpass_helper.php改成了phpass_helper.php。并使用以下代码加载:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
$this->load->helper('Phpass_helper');

但它仍然给我错误提示:无法加载请求的文件: helpers/phpass_helper.php。有人知道它为什么不工作吗?任何帮助都将不胜感激。谢谢。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
class PasswordHash {
var $itoa64;
var $iteration_count_log2;
var $portable_hashes;
var $random_state;

function PasswordHash($iteration_count_log2, $portable_hashes)
{
    $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

    if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
        $iteration_count_log2 = 8;
    $this->iteration_count_log2 = $iteration_count_log2;

    $this->portable_hashes = $portable_hashes;

    $this->random_state = microtime();
    if (function_exists('getmypid'))
        $this->random_state .= getmypid();
}

function get_random_bytes($count)
{
    $output = '';
    if (is_readable('/dev/urandom') &&
        ($fh = @fopen('/dev/urandom', 'rb'))) {
        $output = fread($fh, $count);
        fclose($fh);
    }

    if (strlen($output) < $count) {
        $output = '';
        for ($i = 0; $i < $count; $i += 16) {
            $this->random_state =
                md5(microtime() . $this->random_state);
            $output .=
                pack('H*', md5($this->random_state));
        }
        $output = substr($output, 0, $count);
    }

    return $output;
}

function encode64($input, $count)
{
    $output = '';
    $i = 0;
    do {
        $value = ord($input[$i++]);
        $output .= $this->itoa64[$value & 0x3f];
        if ($i < $count)
            $value |= ord($input[$i]) << 8;
        $output .= $this->itoa64[($value >> 6) & 0x3f];
        if ($i++ >= $count)
            break;
        if ($i < $count)
            $value |= ord($input[$i]) << 16;
        $output .= $this->itoa64[($value >> 12) & 0x3f];
        if ($i++ >= $count)
            break;
        $output .= $this->itoa64[($value >> 18) & 0x3f];
    } while ($i < $count);

    return $output;
}

function gensalt_private($input)
{
    $output = '$P$';
    $output .= $this->itoa64[min($this->iteration_count_log2 +
        ((PHP_VERSION >= '5') ? 5 : 3), 30)];
    $output .= $this->encode64($input, 6);

    return $output;
}

function crypt_private($password, $setting)
{
    $output = '*0';
    if (substr($setting, 0, 2) == $output)
        $output = '*1';

    $id = substr($setting, 0, 3);
    # We use "$P$", phpBB3 uses "$H$" for the same thing
    if ($id != '$P$' && $id != '$H$')
        return $output;

    $count_log2 = strpos($this->itoa64, $setting[3]);
    if ($count_log2 < 7 || $count_log2 > 30)
        return $output;

    $count = 1 << $count_log2;

    $salt = substr($setting, 4, 8);
    if (strlen($salt) != 8)
        return $output;

    # We're kind of forced to use MD5 here since it's the only
    # cryptographic primitive available in all versions of PHP
    # currently in use.  To implement our own low-level crypto
    # in PHP would result in much worse performance and
    # consequently in lower iteration counts and hashes that are
    # quicker to crack (by non-PHP code).
    if (PHP_VERSION >= '5') {
        $hash = md5($salt . $password, TRUE);
        do {
            $hash = md5($hash . $password, TRUE);
        } while (--$count);
    } else {
        $hash = pack('H*', md5($salt . $password));
        do {
            $hash = pack('H*', md5($hash . $password));
        } while (--$count);
    }

    $output = substr($setting, 0, 12);
    $output .= $this->encode64($hash, 16);

    return $output;
}

function gensalt_extended($input)
{
    $count_log2 = min($this->iteration_count_log2 + 8, 24);
    # This should be odd to not reveal weak DES keys, and the
    # maximum valid value is (2**24 - 1) which is odd anyway.
    $count = (1 << $count_log2) - 1;

    $output = '_';
    $output .= $this->itoa64[$count & 0x3f];
    $output .= $this->itoa64[($count >> 6) & 0x3f];
    $output .= $this->itoa64[($count >> 12) & 0x3f];
    $output .= $this->itoa64[($count >> 18) & 0x3f];

    $output .= $this->encode64($input, 3);

    return $output;
}

function gensalt_blowfish($input)
{
    # This one needs to use a different order of characters and a
    # different encoding scheme from the one in encode64() above.
    # We care because the last character in our encoded string will
    # only represent 2 bits.  While two known implementations of
    # bcrypt will happily accept and correct a salt string which
    # has the 4 unused bits set to non-zero, we do not want to take
    # chances and we also do not want to waste an additional byte
    # of entropy.
    $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

    $output = '$2a$';
    $output .= chr(ord('0') + $this->iteration_count_log2 / 10);
    $output .= chr(ord('0') + $this->iteration_count_log2 % 10);
    $output .= '$';

    $i = 0;
    do {
        $c1 = ord($input[$i++]);
        $output .= $itoa64[$c1 >> 2];
        $c1 = ($c1 & 0x03) << 4;
        if ($i >= 16) {
            $output .= $itoa64[$c1];
            break;
        }

        $c2 = ord($input[$i++]);
        $c1 |= $c2 >> 4;
        $output .= $itoa64[$c1];
        $c1 = ($c2 & 0x0f) << 2;

        $c2 = ord($input[$i++]);
        $c1 |= $c2 >> 6;
        $output .= $itoa64[$c1];
        $output .= $itoa64[$c2 & 0x3f];
    } while (1);

    return $output;
}

function HashPassword($password)
{
    $random = '';

    if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
        $random = $this->get_random_bytes(16);
        $hash =
            crypt($password, $this->gensalt_blowfish($random));
        if (strlen($hash) == 60)
            return $hash;
    }

    if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
        if (strlen($random) < 3)
            $random = $this->get_random_bytes(3);
        $hash =
            crypt($password, $this->gensalt_extended($random));
        if (strlen($hash) == 20)
            return $hash;
    }

    if (strlen($random) < 6)
        $random = $this->get_random_bytes(6);
    $hash =
        $this->crypt_private($password,
        $this->gensalt_private($random));
    if (strlen($hash) == 34)
        return $hash;

    # Returning '*' on error is safe here, but would _not_ be safe
    # in a crypt(3)-like function used _both_ for generating new
    # hashes and for validating passwords against existing hashes.
    return '*';
}

function CheckPassword($password, $stored_hash)
{
    $hash = $this->crypt_private($password, $stored_hash);
    if ($hash[0] == '*')
        $hash = crypt($password, $stored_hash);

    return $hash == $stored_hash;
}

}

?>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-12 17:42:36

正如您在Codeigniter文档中所看到的:

与CodeIgniter中的大多数其他系统不同,Helper不是以面向对象的格式编写的。它们是简单的过程性函数。每个辅助函数执行一个特定的任务,而不依赖于其他函数。

要加载帮助器,文件的名称必须类似于"phpass_helper.php“,并且在控制器内部,您可以这样加载

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
$this->load->helper('phpass_helper');

但在您使用"PasswordHash“类的情况下,我建议您将其转换为库,这将更适合您的应用程序,也是一种正确的应用方式。

Creating libraries in Codeigniter

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35356440

复制
相关文章
CoordinatorLayout
CoordinatorLayout作为“super-powered FrameLayout”基本实现两个功能:  1、作为顶层布局  2、调度协调子布局 CoordinatorLayout使用新的思路通过协调调度子布局的形式实现触摸影响布局的形式产生动画效果。CoordinatorLayout通过设置子View的 Behaviors来调度子View。系统(Support V7)提供了AppBarLayout.Behavior, AppBarLayout.ScrollingViewBehavior, F
xiangzhihong
2018/02/01
1.4K0
CoordinatorLayout
Android--CoordinatorLayout基本使用
CoordinatorLayout是在desgin包下的一个用于协调子控件的组件,可以解决绝大部分滑动联动问题,使用方法也很简单,为观察者注册一个Behavior,在Behavior指定要监听的控件(
aruba
2020/07/03
1K0
Android--CoordinatorLayout基本使用
滑动吸顶效果
需求是先滑动里面的列表,滑动到一个位置时外面滑动,外面滑动一段距离后再里面滑动。最初想用 CoordinatorLayout 加 RecyclerView,但效果不好直接用,或者用 NestedScrollView 与 RecyclerView 组合使用。
三流之路
2019/05/21
2.7K0
NestedScrollView 嵌套 ListView 实现滑动折叠效果
引言 最近,在做公司一个design折叠效果的时候遇到个问题,就是我们本身app的方法数太多了,dex分包技术还没搞定。不得不尽量缩减一些不必要的包、类。当我们引入RecyclerView的时候,恰好
用户1127566
2018/06/06
3.5K0
CoordinatorLayout与滚动的处理
本博文专门讲解和CoordinatorLayout相关的知识点,这也是Design Support Library中最重要与最难的部分。
小小工匠
2021/08/16
8190
NestedScrolling机制之CoordinatorLayout.Behavior实战
在上一讲中我们讲了NestedScrolling机制,其实android很多有些常用的控件都是支持NestedScrolling机制的,如RecyclerView,NestedScrollView等,
HelloJack
2018/10/11
9070
NestedScrolling机制之CoordinatorLayout.Behavior实战
Floating Action Button-Android M新控件
浮动操作按钮 (简称 FAB) 是: “一个特殊的promoted操作案例。因为一个浮动在UI之上的圆形图标而显得格外突出,同时它还具有特殊的手势行为”
小小工匠
2021/08/16
1.5K0
自定义 Behavior,实现嵌套滑动、平滑切换周月视图的日历
使用 CoordinateLayout 可以协调它的子布局,实现滑动效果的联动,它的滑动效果由 Behavior 实现。以前用过小米日历,对它滑动平滑切换日月视图的效果印象深刻。本文尝试用自定义 Behavior 实现一个带有这种效果的日历。
CCCruch
2019/07/23
3.4K0
自定义 Behavior,实现嵌套滑动、平滑切换周月视图的日历
淘宝首页Bug!嵌套滑动及NestedScroll
学习嵌套滑动的相关文章: 自定义View事件之进阶篇(一)-NestedScrolling(嵌套滑动)机制. Android NestedScrolling机制完全解析 带你玩转嵌套滑动
胡飞洋
2020/07/23
1.5K0
淘宝首页Bug!嵌套滑动及NestedScroll
用 CoordinatorLayout 处理滚动
原文地址:Handling Scrolls with CoordinatorLayout 原文作者:CODEPATH 译文出自:掘金翻译计划 本文永久链接:github.com/xitu/gold-m… 译者:Feximin 总览 CoordinatorLayout 扩展了完成 Google's Material Design 中的多种滚动效果的能力。目前,此框架提供了几种不需要写任何自定义动画代码就可以(使动画)工作的方式。这些效果包括: 上下滑动 Floating Action Button 以给 Sn
Android 开发者
2018/05/31
4.9K0
Android之MaterialDesign应用技术
  PS:纵观现在大大小小软件的界面都变的比较漂亮,还有一些系统了,比如小米的MIUI,华为的EMUI等,虽然底层都是安卓,但他们的界面多多少少都会不同,谷歌对这个UI也是非常重视的,MaterialDesign就是今天的主角,首先在看这个的同时,要搞清楚什么是Material Design,百度百科解释,中文名:材料设计语言,是由Google推出的全新的设计语言,谷歌表示,这种设计语言旨在为手机、平板电脑、台式机和“其他平台”提供更一致、更广泛的“外观和感觉”。design,中文是设计之意,即“设想和计划
cMusketeer
2018/03/28
1.3K0
Android之MaterialDesign应用技术
MaterialDesign之FloatingActionButton
就是上面这样了,忘说了一件很重要的事情……FloatingActionButton的监听就是最原始的监听!!!接下来到了重头戏了
蜻蜓队长
2018/08/03
7120
MaterialDesign之FloatingActionButton
自定义 Behavior - 仿新浪微博发现页的实现
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gdutxiaoxu/article/details/71732642
程序员徐公
2018/09/17
8820
自定义 Behavior - 仿新浪微博发现页的实现
ViewPager,ScrollView 嵌套ViewPager滑动冲突解决
文章首发地址CSDN:http://blog.csdn.net/gdutxiaoxu/article/details/52939127
全栈程序员站长
2022/09/15
6930
ViewPager,ScrollView 嵌套ViewPager滑动冲突解决
Android studio 最近版安卓pom依赖2020
gridlayout 网格布局 implementation'androidx.gridlayout:gridlayout:1.0.0' drawerlayout 抽屉布局 implementation'androidx.drawerlayout:drawerlayout:1.0.0' NavigationView 侧滑 implementation 'com.google.android.material.navigation.NavigationView:1.0.0' constraintlayout
CaesarChang张旭
2021/01/26
1.4K0
点击加载更多

相似问题

RecyclerView内部的水平RecyclerView CoordinatorLayout内部

32

CoordinatorLayout中的水平RecyclerView

21

带有NestedScrollView和水平滚动RecyclerView的CoordinatorLayout

221

带有NestedScrollView的NestedScrolling,RecyclerView (水平),在CoordinatorLayout内

516

使用RecyclerView的CoordinatorLayout

10
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文