Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

How does it make you feel?

Name: Anonymous 2008-08-19 8:01


$file_id = $db->escape_string(md5_file($file));

Name: Anonymous 2008-08-19 8:24

Quite good, actually.

define("PASS", "Site wide totally random stuff to use as a salt. Hammer on your keyboard for 30 seconds, please.");
define("passHashingIters", 512);
function passhash($password, $raw = true)
{
    $p = str_split(PASS);
    $pl = strlen(PASS);
    if (passHashingIters > 1) {
        for ($i = 0; $i !== passHashingIters - 1; ++$i) {
            $password = hash('sha512', $password . $p[$i%$pl], true);
        }
    }
    return hash('sha512', $password, $raw);
}


How about this?

Name: Anonymous 2008-08-19 8:39

>>2
Keep it simple, stupid.

Name: Anonymous 2008-08-19 8:43

Name: Anonymous 2008-08-19 9:14

>>3
Keep it secure, senile.

Name: Anonymous 2008-08-19 9:21

>>1
Depends on the size of the file, and the usage for that id.

Name: Anonymous 2008-08-19 9:51

>>6
escape_string() is a mysqli method equivalent to mysqli_real_escape_string. So basically, the md5 sum is escaped before database insertion.
And so the question is, what's the point in escaping md5 checksums?

Name: Anonymous 2008-08-19 10:45

>>2
Brain-damaged concept aside, using str_split with only one argument displays ignorance of the language.

Name: Anonymous 2008-08-19 11:04

>>8
Broken language aside, str_split only needs one argument1.

                                        
References: [1] http://us2.php.net/str_split

Name: Anonymous 2008-08-19 11:08

>>9
Just because the second argument is optional doesn't mean it's not retarded to use the function with only one argument. PHP strings are already arrays of chars, and can already be used as such. All str_split with one argument does is waste time with a function call that does nothing.

Name: Anonymous 2008-08-19 11:22

>>10
I disagree. The goal is to treat the string as a character array, which is what str_split does --

$ php -r 'print_r( str_split( "have a wank" ) );'
Array
(
    [0] => h
    [1] => a
    [2] => v
    [3] => e
    [4] => 
    [5] => a
    [6] => 
    [7] => w
    [8] => a
    [9] => n
    [10] => k
)

Name: Anonymous 2008-08-19 11:35

>>10
You're right about the char-as-array-part. I think I made something that required it and then changed it back. Or I was drunk that day.

Name: >11 2008-08-19 11:38

>>10
To clarify, I'm not disagreeing that >>2's use of str_split is stupid (or that >>2 is stupid in the whole), but rather that there are cases where it is useful to use str_split.

PHP strings are already arrays of chars, and can already be used as such.
This is not correct. PHP strings support indexing via operator[] (and operator{} pre-PHP6), but they are not arrays. This can be illustrated with a simple example:

$ php -r 'print_r( is_array( "asd" ) ? "Arrays\n" : "Not arrays\n" );'
Not arrays


While they have the same indexing syntax as arrays, they lack other features, like iterative functionality --

$ php -r 'foreach( "asd" as $a ) echo( "$a\n" );'
Warning: Invalid argument supplied for foreach() in Command line code on line 1

$ php -r 'foreach( str_split( "asd" ) as $a ) echo( "$a\n" );'
a
s
d


In conclusion please read SICP.

Name: Anonymous 2008-08-19 11:39

>>11
For all relevant purposes, strings are character arrays.

~$ php -r '$a = "string"; $a[3] = "u"; echo $a;'
strung

Name: Anonymous 2008-08-19 11:40

>>14
Race condition detected. Please refer to >>13.

Name: Anonymous 2008-08-19 11:40

>>7
There is no point. md5 hashes never have any special characters in them. I'm surprised it took seven responses for someone to catch that.

Name: Anonymous 2008-08-19 11:42

>>13
Fair enough, but foreach aside, you'd be hard-pressed to find a context where the distinction matters.
To be honest, I didn't know it didn't work with foreach, as it does in Python. I guess I overestimated PHP again.

Name: Anonymous 2008-08-19 11:44

>>16
Only two or three people here know how to program, and even fewer know enough PHP to realise PHP's md5 returns the hash as a string of hex digits rather than a binary blob.

Name: Anonymous 2008-08-19 11:46

>>10
Ah, wait. It's a constant that's really defined in a different file and used throughout the app, and you cant access a constant as an array, and because I was going to use it as an array, I didn't think about the string stuff, and if my sentences are long it's because I haven't slept in two days, which is somehow also related to why I can muster up the self-confidence to actually interact with other people.

By the way Mr. Expert, does it copy on write with constants too, so $p = PASS; doesn't use more RAM?

Name: Anonymous 2008-08-19 11:47

>>17
Yeah, PHP's foreach is a hackish builtin which can only operate on arrays. Add to that the weird type juggling semantics (where, at any time each variable has a distinct type, but can be implicitly converted to any another type to fulfill the needs of an operation) and you've got a giant mess.

Python's foreach works with anything that provides an __iter__ method, and practically everything that you'd want to iterate over does. <3 FIOC.

Name: Anonymous 2008-08-19 11:51

>>18
string md5_file  ( string $filename  [, bool $raw_output  ] )

Name: Anonymous 2008-08-19 11:52

>>19
If you're that worried about performance, copy on write semantics are the least of your worries.

Name: Anonymous 2008-08-19 11:53

>>22
I'm not, but I'm wondering. Curiosity for curiosity's sake.

Name: Anonymous 2008-08-19 11:53

>>20
foreach also iterates through objects (to some extent)

Name: Anonymous 2008-08-19 11:58

>>24
Yes, yes, we all know about the traversable interface.

Name: Anonymous 2008-08-19 12:00

>>23
I honestly don't know; >>22 was just a cop-out.

>>24
That's pretty cool, I didn't know it did that1.
                                
References: [1] http://us.php.net/manual/en/language.oop5.iterations.php

Name: Anonymous 2008-08-19 12:04

whats an itaration?

Name: Anonymous 2008-08-19 12:04

Name: Anonymous 2008-08-19 12:07

>>28
wtf is travasable and wtf is itarration?

Name: Anonymous 2008-08-19 12:15

>>29
Confusing words made by evil men to make your anus feel haxed.

Name: Anonymous 2008-08-19 12:19

r u fuckin me or wat?

Name: Anonymous 2008-08-19 12:22

r u hackin my anus yet?

Name: Anonymous 2008-08-19 12:36

wtf do u want? wats anus haxin?

Name: Anonymous 2008-08-19 12:59

Name: Anonymous 2008-08-19 14:36

>>34
I just threw up a little in my mouth.

Name: Anonymous 2011-12-27 14:35

`
>Not getting 36GET
>2008

Don't change these.
Name: Email:
Entire Thread Thread List