php-general Digest 13 Jun 2008 13:43:20 -0000 Issue 5512

Topics (messages 275299 through 275324):

Re: a questoin about the "#" char
        275299 by: Daniel Brown
        275300 by: DeadTOm
        275302 by: Chris
        275303 by: Robert Cummings
        275305 by: Robert Cummings
        275324 by: Daniel Brown

Re: unlink oddity
        275301 by: Chris

Re: class? package?
        275304 by: Shelley
        275306 by: Shelley
        275318 by: Iv Ray

Re: PHP connection to external application
        275307 by: hce
        275311 by: Per Jessen
        275315 by: Iv Ray

Re: PHP code will not work
        275308 by: Joseph Subida

Problem with php execution and variables
        275309 by: SenTnel

Apache RewriteRule Help!!!!
        275310 by: Miguel J. Jiménez

Re: HTML 5
        275312 by: Richard Heyes
        275322 by: Eric Butera

why are passwords stored encrypted in databases even when the data they protect 
is stored in the same database?
        275313 by: Dietrich Bollmann
        275314 by: Per Jessen
        275317 by: M. Sokolewicz
        275319 by: Dietrich Bollmann
        275321 by: M. Sokolewicz

Re: UK PHP Host/Developer Required
        275316 by: Iv Ray

PDF to images or something similar
        275320 by: Ray Mckoy
        275323 by: Per Jessen

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
On Thu, Jun 12, 2008 at 8:18 PM, Sebastian Camino
<[EMAIL PROTECTED]> wrote:
> Hello,
>
> I want to know what the "#" char does. On a website I was working at, I
> tried to open a file with a "#" in it's name and I got an error. So I'd
> really appreciate any help to know how to avoid the error and what  does the
> character do.

    That's pretty vague there, Sebastian.  What error are you getting?
 What operating system?  How are you attempting to open the file?
What is the file name?

    Details, man!  ;-P

-- 
</Daniel P. Brown>
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

--- End Message ---
--- Begin Message --- Inside a php script the '#' denotes the beginning of a comment. I don't know that it has any use at all in the address line. What specifically is the error? I'd guess that php would ignore the rest of the line following the '#' and so this could generate any number of errors depending on what information is carried in the address and what that info is for. I'm not aware of any way to scan the address within php, this might need to be done with a proxy of some kind. If it can be done or if you can talk to the owner of the site you're trying to get the file from, you might try replacing the '#' with a '%23'.

-Allen
Hello,

I want to know what the "#" char does. On a website I was working at, I tried to open a file with a "#" in it's name and I got an error. So I'd really appreciate any help to know how to avoid the error and what does the character do.

Thanks a lot

Sebastian



--- End Message ---
--- Begin Message ---
Sebastian Camino wrote:
> Hello,
> 
> I want to know what the "#" char does.

In a url it's an anchor tag (http://www.w3schools.com/HTML/html_links.asp).

In php it's used to mark a comment.

<?php
# this is a comment and not executed.
?>

It means nothing specific in a filename.

-- 
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
On Fri, 2008-06-13 at 11:10 +1000, Chris wrote:
> Sebastian Camino wrote:
> > Hello,
> > 
> > I want to know what the "#" char does.
> 
> In a url it's an anchor tag (http://www.w3schools.com/HTML/html_links.asp).
> 
> In php it's used to mark a comment.
> 
> <?php
> # this is a comment and not executed.
> ?>
> 
> It means nothing specific in a filename.

CVS conflict?? :)

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


--- End Message ---
--- Begin Message ---
On Thu, 2008-06-12 at 22:03 -0400, Robert Cummings wrote:
> On Fri, 2008-06-13 at 11:10 +1000, Chris wrote:
> > Sebastian Camino wrote:
> > > Hello,
> > > 
> > > I want to know what the "#" char does.
> > 
> > In a url it's an anchor tag (http://www.w3schools.com/HTML/html_links.asp).
> > 
> > In php it's used to mark a comment.
> > 
> > <?php
> > # this is a comment and not executed.
> > ?>
> > 
> > It means nothing specific in a filename.
> 
> CVS conflict?? :)

Actually, I should say... the backup file due to a CVS conflict or auto
merge.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


--- End Message ---
--- Begin Message ---
On Thu, Jun 12, 2008 at 10:05 PM, Robert Cummings <[EMAIL PROTECTED]> wrote:
>>
>> CVS conflict?? :)
>
> Actually, I should say... the backup file due to a CVS conflict or auto
> merge.

    Which is funny to see when you're editing a Vim-backup of a
backed-up file and it gets swept up by an automated CVS commit script.
 You wind up with something like the following:

    #.a.php.bak.swp~

    This happened when I was double-checking a function in a script I
was working on about a year ago.  The file looked like a toddler's
drawing of a "choo-choo train" in the TTY.

-- 
</Daniel P. Brown>
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

--- End Message ---
--- Begin Message ---
> 
> function saveRecord ($db,$POST) {
>    $bd = "/absolute_path_to_document_root";
>    $fp = "/path_to_files_from_document_root/";
>    $ud = $bd . $fp;

<snip>

>          $path = $ud.$file; // absolute path to newly named file
>          if ($fail || !$name || !$temp) continue;
> //         @unlink($ud.$file);
>          @move_uploaded_file($temp, $path);
>          @chmod($path, 0777);

Why not just unlink($path) ? It's the same thing but you take 2
variables out of the problem.

While you're trying to debug this remove the '@' signs. An error message
will be particularly useful.

Check your logs if you can, otherwise turn up error reporting and
display errors until you work out what's going on.

error_reporting(E_ALL);
ini_set('display_errors', true);



-- 
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
On Wed, Jun 11, 2008 at 12:02 PM, Larry Garfield <[EMAIL PROTECTED]>
wrote:

> On Tuesday 10 June 2008, Shelley wrote:
> > Hi all,
> >
> > If you are designing with OO principles, could you give an explanation of
> > what is the difference classes and packages?
> >
> > Several principles talks about classes and packages, such as:
> > The classes in a package are reused together. If you reuse one of the
> > classes in a package, you reuse them all.
> >
> > but few explains the difference between them.
> >
> > When I was summarizing the OO principles, that question confused me:
> >
> http://phparch.cn/index.php/php/43-php-advanced-programming/170-principles-
> >of-object-oriented-design
> >
> > Thanks in advance. :)
>
> A class is a syntactic way of grouping behavior and data together in an
> encapsulated fashion (at least that's the PHP definition).
>
> A formal package is a syntactic way of grouping related classes together,
> either for easier distribution, somewhat tighter coupling, or syntactic
> sugar.  For instance, you could have 5 classes that make up your "Database
> abstraction" package; they're all discrete, but all work in concert.
>
> PHP does not have a syntactic "package" concept.  The closest thing would
> be
> namespaces as implemented in PHP 5.3, but that's not out yet.  Many systems
> emulate packages with verbose class naming (eg, Database_Connection,
> Database_Query, Database_Transaction, Database_Query_Select, etc.), but I
> personally find that ugly. :-)
>
> Thank you very much for the explanation.
I think I got some.
Maybe I am already using them:
I am working on a sns site, and now my practice is grouping classes of a
function
(i.e. subscription) together. When I need it, just load the "package":
subscription.

Right? ;)
-- 
Regards,
Shelley

--- End Message ---
--- Begin Message ---
On Thu, Jun 12, 2008 at 3:01 PM, Iv Ray <[EMAIL PROTECTED]> wrote:

> Shelley wrote:
>
>> Probably you have noticed this:
>> The classes in a package are reused together. If you reuse one of the
>> classes in a package, you reuse them all.
>> If that's the case, then why not just use one class as one package?
>> What's the point of splitting a package into several classes? :-(
>>
>
> I think somebody already answered.
>
> It is actually up to you.
>
> My grandmother used to write letters starting with a capital letter,
> writing the whole letter as one long sentence and ending with a dot. This
> would perhaps confuse most high school teachers, but in her case it somehow
> worked :)
>
> If we take this worn out example - if you have a class "dog" and a class
> "cat" - it becomes quite clear why you need several classes. You can put
> them in a package called "animals" - but as other people already noted, the
> "packages" in php have only a symbolic role, just for clarity of code
> organization.
>
Yeah, that's it.



-- 
Regards,
Shel

--- End Message ---
--- Begin Message ---
Shelley wrote:
I am working on a sns site, and now my practice is grouping classes of a
function

"classes of a function"... perhaps "classes related to certain functionality"?

(i. e. subscription) together. When I need it, just load the "package":
subscription.

Right? ;)

Hm... I do not know your project, but to have many classes just to handle subscription, sounds a bit too much to me. Why don't you have a class called "subscription", which might even extend a class called "person" or "user" - the "subscription" class can have methods, for instance "subscribe" and "unsubscribe", and because "subscription" extends "person" or "user" - it already "knows" who is the "person"/"user".

And then, for example, to subscribe a "person"/"user", you do -

$subscription->subscribe($list_id);

Other possible actions -

$subscription->un_subscribe($list_id);
$subscription->is_subscriber($list_id);
$subscription->lists();

etc.

This way class "subscription" "packs" the methods needed to handle subscription related activities, so in your own jargon, this "class" is a "package".

Of course, if the subscription process is extremely complicated, you can have more classes.

Iv

--- End Message ---
--- Begin Message ---
On Thu, Jun 12, 2008 at 9:30 PM, Stut <[EMAIL PROTECTED]> wrote:
> On 12 Jun 2008, at 12:20, hce wrote:
>>
>> What is the best way for a PHP web application to connect to an
>> external application written by C in Linux OS?
>>
>> (1) Can PHP directly call external C functions, or similar solution?
>
> No, but you can wrap the C functions in a PHP extension.

Ok, that is not an option.

>> (2) Can PHP pass messages to message queue which external C program can
>> access?
>
> Depends on the implementation of the queue, but the answer is almost
> certainly yes.

I am not certain if the msg_send / msg_receive in PHP can talk to the
external C program msg_send  / msg_receive as PHP and external C
program are in different processes, different memory spaces. Unless
wrap the C functions in a PHP extension as your suggested in (1).


>> (3) Socket connection between the PHP and external C program.
>
> This would usually be my preferred choice unless there is a particular
> reason to avoid this in which case I would go down the PHP extension route.
>
> A lot will depend on what the C code is doing and how your PHP scripts will
> interact with it.

Let me first describe the requirement more:

The C program is a major business server which accesses the database,
exchanges information to other remote servers and it has many other
background tasks running concurrently for doing monitor, statistic
report, real time update data, etc.

The PHP web application connects to the C program to get data and
information and to display on user's web browser. I know socket works
between the PHP and external C server, but there are many concerns
depends on different implementations:

(a) A simple way is if for every PHP request, it opens socket, sends a
request and gets a response from the C server then closes the socket.
It should work, but I am not sure:
   (i) if the open / close socket per request will cause delays and
performance issues.
   (ii) What is the maximum number concurrent requests in a PHP web
application? Will the maximum socket number  / or port number (up to
2^16) be a bottleneck for large number of concurrent requests (hundred
and thousands)?

(b) If for all PHP requests share only one socket to connect to the
external C server, I am not sure if the PHP is able to do multiplex
responses for each request as the PHP is stateless.

Thank you.

Jim

--- End Message ---
--- Begin Message ---
hce wrote:

> I am not certain if the msg_send / msg_receive in PHP can talk to the
> external C program msg_send  / msg_receive as PHP and external C
> program are in different processes, different memory spaces. 

System V message queues are intended for just that; IPC = Inter Process
Communication. 

> (a) A simple way is if for every PHP request, it opens socket, sends a
> request and gets a response from the C server then closes the socket.
> It should work, but I am not sure:
>    (i) if the open / close socket per request will cause delays and
> performance issues.

They will cause both delays and performance issues.  But whether these
will matter for your use is a different question.  The process you've
describe (open,get,close) is no different to sending an email or
getting a web-page.  People send a lot of email and serve a lot of
webpages without major performance issues :-)

> (ii) What is the maximum number concurrent requests in a PHP web
> application? 

That's up to your webserver - if it's big enough, you can serve a lot of
concurrent requests. 

> Will the maximum socket number  / or port number (up to 2^16) be a
> bottleneck for large number of concurrent requests (hundred 
> and thousands)?

Probably not. 

> (b) If for all PHP requests share only one socket to connect to the
> external C server, I am not sure if the PHP is able to do multiplex
> responses for each request as the PHP is stateless.

"PHP is stateless" ??  PHP is a scripting language, not a protocol. 
Besides, it would take quite a bit of work to make your thousands of
concurrent PHP requests share a single socket. 


/Per Jessen, Zürich


--- End Message ---
--- Begin Message ---
hce wrote:
Let me first describe the requirement more:

The C program is a major business server

I would not connect applications on low level.

I would think of a "web services" type of interface - http request and xml response (Steven suggested, for example, SOAP - but it does not need to be that complicated).

The has several benefits -

a) Clearly defined, the "web services" gate will not be affected by changes in the C program.

b) You can use the "web services" gate to plug not only your php application, but any other application that can (be made to) talk "web services".

c) The implementation of the php application, in this case, will be trivial, resulting in cheaper developers/development/maintenance/expansion.

   (ii) What is the maximum number concurrent requests in a PHP web
application? Will the maximum socket number  / or port number (up to
2^16) be a bottleneck for large number of concurrent requests (hundred
and thousands)?

Nobody can tell you this for your existing infrastructure. The only thing you can do is try and optimize.

Iv

--

--- End Message ---
--- Begin Message ---
Daniel Brown wrote:
On Wed, Jun 11, 2008 at 11:51 PM, Joseph Subida <[EMAIL PROTECTED]> wrote:
Hi.

I am new to PHP. I found a tutorial that said to copy and paste the code
into a .php document and open it in my browser:

<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>

I'm pretty sure PHP is enabled on my computer. I've tested code such as:

    PHP is definitely on your system.

[snip!]

The error I get when I try


<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>

is

Parse error: syntax error, unexpected T_VARIABLE in
/Library/WebServer/Documents/test.php on line 106

    What is the code on lines 105 and 106 of test.php?  If there's
nothing on line 105, please send us the immediately-preceding code.


105: <?php
106: echo $_SERVER['HTTP_USER_AGENT'];
107: ?>

All the code before line 105 is code that I've been messing around with. I tried testing those three lines in its own file. But I still get the same error:

Parse error: syntax error, unexpected T_VARIABLE in /Library/WebServer/Documents/error.php on line 2


    By the way, a T_VARIABLE is just a variable --- anything beginning
with a $dollar_sign.


--- End Message ---
--- Begin Message ---
Hello!

Im new to programing and this is the situation I have with a first level
basic php tutorial: One of the samples uses a simple order form that submits
to this page and is supposed to return the values entered on that form. This
is the code not working:


<?
  echo "<p>Your order"; // Start printing order

  echo date("jS F,H:i ");
  echo "<br>";
  echo "<p>This is your order:";
  echo "<br>";
  echo $actionqty." ActionScript<br>";
  echo $photoqty." Photoshop<br>";
  echo $flashqty." Flash MX<br>";
?>


The problem is that with this code my page does not shows the amounts
entered in he form, but the tutorial works with the exact same code, then,
the same tutorial showed another "long way" to do the same thing and is
using this other code that works on my page:

<?
  echo "<p>Your order"; // Start printing order

  echo date("jS F,H:i ");
  echo "<br>";
  echo "<p>This is your order:";
  echo "<br>";
  echo $HTTP_POST_VARS["actionqty"]." ActionScript<br>";
  echo $HTTP_POST_VARS["photoqty"]." Photoshop<br>";
  echo $HTTP_POST_VARS["flashqty"]." Photoshop<br>";
?>

I want to use the short way, why doesn't work on my server? Do I have to set
some settings in php configuration to be able to use php in the short
format?

Thanks !
-- 
View this message in context: 
http://www.nabble.com/Problem-with-php-execution-and-variables-tp17816172p17816172.html
Sent from the PHP - General mailing list archive at Nabble.com.


--- End Message ---
--- Begin Message ---
Hi, I am having a little problem here, I have a .htaccess that looks
thus:

RewriteEngine on
RewriteBase /INDEX
RewriteRule ^(.*\.(log|sqlite))$ index.php [L]
RewriteRule ^(.*\.(js|css|png|jpg|gif|xml))$  [L]
RewriteRule ^(.*)$ index.php?m=$1 [L,QSA]

When I type "http://foo/INDEX/mp3"; it goes [internally] to
"http://foo/INDEX/index.php?m=mp3";. Great so far... The problem is when
I try to forbid access to "http://foo/INDEX/index.php?m=mp3"; for the
user. I mean if the user types "http://foo/INDEX/index.php?m=mp3"; I
want the apache to send a redirect code or something...

I tried:

RewriteCond %{IS_SUBREQ} false
RewriteRule index.php - [L,NS,R=404]

...just below  the line "RewriteBase /INDEX" but when I do this, it just
redirect *always* even if I type "http://foo/INDEX/mp3";.

How can I make apache work fine with "http://foo/INDEX/mp3"; and
redirect to an error page (or moved url or wahtever)
with "http://foo/INDEX/index.php?m=mp3"; (from the client view)

thanks for the help


---
.---------------------------------------------------------.
| Miguel J. Jiménez                                       |
| Sector Público, ISOTROL S.A.                            |
| [EMAIL PROTECTED]                                   |
:---------------------------------------------------------:
| KeyID 0xFFE63EC6             hkp://pgp.rediris.es:11371 |
:---------------------------------------------------------:
| Edificio BLUENET, Avda. Isaac Newton nº3, 4ª planta.    |
| Parque Tecnológico Cartuja '93, 41092 Sevilla (ESP).    |
| Tlfn: +34 955 036 800 (ext.1805) - Fax: +34 955 036 849 |
| http://www.isotrol.com                                  |
:---------------------------------------------------------:
| UTM ED-50             X:765205.09 Y:4144614.91 Huso: 29 |
:---------------------------------------------------------:
|   "Me dijeron: 'instala Windows, se listo'; así que     |
| instalé primero Windows y luego fui listo y lo borré    |
| para instalar Linux"                                    |
'---------------------------------------------------------'

Attachment: signature.asc
Description: PGP signature


--- End Message ---
--- Begin Message ---
i suppose i put too much faith in the right hand nav on the w3cschools site
=/

http://www.w3.org/ is the site to use for up to date standards.

--
Richard Heyes

        Employ me:
http://www.phpguru.org/cv

+----------------------------------------+
| Access SSH with a Windows mapped drive |
|    http://www.phpguru.org/sftpdrive    |
+----------------------------------------+

--- End Message ---
--- Begin Message ---
On Fri, Jun 13, 2008 at 4:35 AM, Richard Heyes <[EMAIL PROTECTED]> wrote:
>> i suppose i put too much faith in the right hand nav on the w3cschools
>> site
>> =/
>
> http://www.w3.org/ is the site to use for up to date standards.


Well that is a bit ironic as just the other day you said you didn't
care about standards[1] as far as redirects were concerned.  :P

[1] http://www.mail-archive.com/[EMAIL PROTECTED]/msg228512.html

--- End Message ---
--- Begin Message ---
Hi,

As far as I remember, in all books I read about PHP and SQL, the
password was stored in an encrypted form, even when all the data which
should be protected by the password was stored in the same database.

Can anybody tell me what is the motivation behind this approach?
If somebody hacks the database, he has the data anyway; if he doesn't,
he can't retrieve the password, encrypted or not.

I am asking because I would like to implement a simple file server.
A user would upload his files and get them listed on his user page.  If
he wants to allow some other person to download the file, he pushes a
button beside the file entry in the listing and a page opens where he
can enter the email of the other person.  An email is send with the link
where the file can be found and a password included...

The person who asked me to write this file server wants everybody who to
receive the same link together with the same password for the same file.
In order to implement this approach, the password has to be stored
somewhere...

I thought about storing the password as it is in the database - but
somehow wonder why this never was done in any of the books I read...

By the way: in most cases, when pushing the "I forgot my password"
button, an email with a user name and a link to activate the password is
generated.  Anybody who gets into the possession of the email could
access the data...  Should I rather send two emails, one with the link,
one with the new password?

Thanks for your help :)

Dietrich



--- End Message ---
--- Begin Message ---
Dietrich Bollmann wrote:

> As far as I remember, in all books I read about PHP and SQL, the
> password was stored in an encrypted form, even when all the data which
> should be protected by the password was stored in the same database.
> 
> Can anybody tell me what is the motivation behind this approach?

The general idea is that only one person should have the password in
clear text.  If you store it as clear text, anyone who's got access to
the database can read the password.  

> The person who asked me to write this file server wants everybody who
> to receive the same link together with the same password for the same
> file. 

Well, if _lots_ of people have the password anyway, there's no need to
be secretive about it :-)

> By the way: in most cases, when pushing the "I forgot my password"
> button, an email with a user name and a link to activate the password
> is generated.  Anybody who gets into the possession of the email could
> access the data...  Should I rather send two emails, one with the
> link, one with the new password?

If you're _really_ converned about this, you send a new password by
recorded/registered mail (Einschreiben). 


/Per Jessen, Zürich


--- End Message ---
--- Begin Message ---
Dietrich Bollmann wrote:
Hi,

As far as I remember, in all books I read about PHP and SQL, the
password was stored in an encrypted form, even when all the data which
should be protected by the password was stored in the same database.

Can anybody tell me what is the motivation behind this approach?
If somebody hacks the database, he has the data anyway; if he doesn't,
he can't retrieve the password, encrypted or not.

I am asking because I would like to implement a simple file server.
A user would upload his files and get them listed on his user page.  If
he wants to allow some other person to download the file, he pushes a
button beside the file entry in the listing and a page opens where he
can enter the email of the other person.  An email is send with the link
where the file can be found and a password included...

The person who asked me to write this file server wants everybody who to
receive the same link together with the same password for the same file.
In order to implement this approach, the password has to be stored
somewhere...

I thought about storing the password as it is in the database - but
somehow wonder why this never was done in any of the books I read...

By the way: in most cases, when pushing the "I forgot my password"
button, an email with a user name and a link to activate the password is
generated.  Anybody who gets into the possession of the email could
access the data...  Should I rather send two emails, one with the link,
one with the new password?

Thanks for your help :)

Dietrich

Assuming that noone will ever get direct access to your database or is able to access the password directly: there is no need for any type of encryption. However, people usually write code which may (and will most of the time) containt exploitable sections which might give a malicious user the ability to get a dump of the database. A password dump is always interesting, since it gives a LOT of information. People usually don't use 1 password per login, but rather have a "standard password" for most things. Now, if it were unprotected, the person getting the information can instantly log in as that user, or if he wants might even take over that person's identity in other places (rare, but it happens). If it were protected by encryption of some kind then it would first need to be decrypted to be usable (unless there is a designflaw which makes this unnecessery as has been the case in a few messageboards a few years ago). Now, you can either encrypt or hash your passwords. Hashes are one-way, encryption two-way. If the malicious user gets hold of a hash: he'll still not have anything useful in his hands. He might make a reverse lookup table and figure out the password from that (though there's an infinite number of possible inputs for each single [hash] output), but add a salt and don't put that in the database and the user has a low chance of ever finding out what it was. But, just as the malicious user can't figure out what the password was, neither can you: so goodby lost-password feature. Instead you'd have to regenerate a new password and send that over, or do some other fancy magic which doesn't involve sending the current password as-is, since you don't know it either. If you were to use encryption there, you could always decrypt it. If you have the key. Storing the key separately from the encrypted password would make this quite safe. enctpyed_string = (data + key), if you know neither the data nor the key, things get very tough. Because you know the key, you can figure out the password and make a forgot-password feature easily which sends out the actual password. But, because your key is publicly available (if your page has to use it, then it's automatically publicly available, maybe not easily, but a malicious user which managed to get hold of a full password table, could just aswell get hold of the key for the encryption)! Putting in neither, so just keeping the passwords in their plain form is safe. As long as noone _ever_ sees them. Guarantee that and you won't have to bother with hashing/encrypting. If you can't guarantee it, build in some extra safety in the form of hashing and/or encrypting.

hope that explains it all a bit,
- tul


--- End Message ---
--- Begin Message ---
Hi tul, 

So this was a very long and informative answer :)
Thank you very much!

On Fri, 2008-06-13 at 12:02 +0200, M. Sokolewicz wrote:
> [...] However, people usually write code which may (and will most 
> of the time) containt exploitable sections which might give a malicious 
> user the ability to get a dump of the database. A password dump is 
> always interesting, since it gives a LOT of information. People usually 
> don't use 1 password per login, but rather have a "standard password" 
> for most things.

So if the user is allowed to change his password, it should be encrypted
always as there are chances that the same password is used at some other
place?  That makes a lot of sense to me :)

If all passwords are generated by the system on the other hand and the
user is not allowed to change his password, if further all the protected
data is in the same database as the password, there would be no need for
encrypting the passwords following your argumentation?

But if some information is stored outside the database - in my case
(simple file server) for example, the database only contains the file
meta-data while the files themselves are stored in some data directory
on the server - some malicious user who would have broken into the
database could get hold of the files if the passwords are stored
unencrypted;  if some encryption scheme would have been used on the
other hand the data found in the database wouldn't be of any use at all?

And if the password should be recoverable some encryption with a key
stored somewhere else would force the hacker to break into two systems,
the database itself and the system which is used to store the key.

That makes sense also.  I didn't think about the fact that database and
a directory on the server are two different things which would have to
be hacked separately.  So I am happy about writing my mail and getting
such a nice answer before implementing some stupid password logic
myself :)

> Now, if it were unprotected, the person getting the information can 
> instantly log in as that user, or if he wants might even take over that 
> person's identity in other places (rare, but it happens). If it were 
> protected by encryption of some kind then it would first need to be 
> decrypted to be usable (unless there is a designflaw which makes this 
> unnecessery as has been the case in a few messageboards a few years ago).
> Now, you can either encrypt or hash your passwords. Hashes are one-way, 
> encryption two-way. If the malicious user gets hold of a hash: he'll 
> still not have anything useful in his hands. He might make a reverse 
> lookup table and figure out the password from that (though there's an 
> infinite number of possible inputs for each single [hash] output), but 
> add a salt and don't put that in the database and the user has a low 
> chance of ever finding out what it was. But, just as the malicious user 
> can't figure out what the password was, neither can you: so goodby 
> lost-password feature. Instead you'd have to regenerate a new password 
> and send that over, or do some other fancy magic which doesn't involve 
> sending the current password as-is, since you don't know it either.
> If you were to use encryption there, you could always decrypt it. If you 
> have the key. Storing the key separately from the encrypted password 
> would make this quite safe. enctpyed_string = (data + key), if you know 
> neither the data nor the key, things get very tough. Because you know 
> the key, you can figure out the password and make a forgot-password 
> feature easily which sends out the actual password.
> But, because your key is publicly available (if your page has to use it, 
> then it's automatically publicly available, maybe not easily, but a 
> malicious user which managed to get hold of a full password table, could 
> just aswell get hold of the key for the encryption)!
> Putting in neither, so just keeping the passwords in their plain form is 
> safe. As long as noone _ever_ sees them. Guarantee that and you won't 
> have to bother with hashing/encrypting. If you can't guarantee it, build 
> in some extra safety in the form of hashing and/or encrypting.
> 
> hope that explains it all a bit,
> - tul

Yes.  A bit.  I am actually impressed.  But I better read some more
redundant book about intelligent malicious users as I still feel like
not understanding everything of what you said completely.

...any nice book recommendation for naive people like me :?

So how about the following solution to my simple file-server problem:

I generate a new url for every user who is allowed to download a file
and a private password for every new url.  Using this approach, the same
file will be downloaded by different users via different urls and
passwords.  The password for an url is stored in the database encrypted
and send over to the user unencrypted per email.  Of course this makes
some more logic and tables necessary - and a new row for every user also
- but who cares :)  What do you think?

Thanks for your interesting explanation!
Dietrich




--- End Message ---
--- Begin Message ---
Dietrich Bollmann wrote:
Hi tul,
So this was a very long and informative answer :)
Thank you very much!

On Fri, 2008-06-13 at 12:02 +0200, M. Sokolewicz wrote:
[...] However, people usually write code which may (and will most of the time) containt exploitable sections which might give a malicious user the ability to get a dump of the database. A password dump is always interesting, since it gives a LOT of information. People usually don't use 1 password per login, but rather have a "standard password" for most things.

So if the user is allowed to change his password, it should be encrypted
always as there are chances that the same password is used at some other
place?  That makes a lot of sense to me :)

If all passwords are generated by the system on the other hand and the
user is not allowed to change his password, if further all the protected
data is in the same database as the password, there would be no need for
encrypting the passwords following your argumentation?

But if some information is stored outside the database - in my case
(simple file server) for example, the database only contains the file
meta-data while the files themselves are stored in some data directory
on the server - some malicious user who would have broken into the
database could get hold of the files if the passwords are stored
unencrypted;  if some encryption scheme would have been used on the
other hand the data found in the database wouldn't be of any use at all?

And if the password should be recoverable some encryption with a key
stored somewhere else would force the hacker to break into two systems,
the database itself and the system which is used to store the key.

That makes sense also.  I didn't think about the fact that database and
a directory on the server are two different things which would have to
be hacked separately.  So I am happy about writing my mail and getting
such a nice answer before implementing some stupid password logic
myself :)

Now, if it were unprotected, the person getting the information can instantly log in as that user, or if he wants might even take over that person's identity in other places (rare, but it happens). If it were protected by encryption of some kind then it would first need to be decrypted to be usable (unless there is a designflaw which makes this unnecessery as has been the case in a few messageboards a few years ago). Now, you can either encrypt or hash your passwords. Hashes are one-way, encryption two-way. If the malicious user gets hold of a hash: he'll still not have anything useful in his hands. He might make a reverse lookup table and figure out the password from that (though there's an infinite number of possible inputs for each single [hash] output), but add a salt and don't put that in the database and the user has a low chance of ever finding out what it was. But, just as the malicious user can't figure out what the password was, neither can you: so goodby lost-password feature. Instead you'd have to regenerate a new password and send that over, or do some other fancy magic which doesn't involve sending the current password as-is, since you don't know it either. If you were to use encryption there, you could always decrypt it. If you have the key. Storing the key separately from the encrypted password would make this quite safe. enctpyed_string = (data + key), if you know neither the data nor the key, things get very tough. Because you know the key, you can figure out the password and make a forgot-password feature easily which sends out the actual password. But, because your key is publicly available (if your page has to use it, then it's automatically publicly available, maybe not easily, but a malicious user which managed to get hold of a full password table, could just aswell get hold of the key for the encryption)! Putting in neither, so just keeping the passwords in their plain form is safe. As long as noone _ever_ sees them. Guarantee that and you won't have to bother with hashing/encrypting. If you can't guarantee it, build in some extra safety in the form of hashing and/or encrypting.

hope that explains it all a bit,
- tul

Yes.  A bit.  I am actually impressed.  But I better read some more
redundant book about intelligent malicious users as I still feel like
not understanding everything of what you said completely.

...any nice book recommendation for naive people like me :?

So how about the following solution to my simple file-server problem:

I generate a new url for every user who is allowed to download a file
and a private password for every new url.  Using this approach, the same
file will be downloaded by different users via different urls and
passwords.  The password for an url is stored in the database encrypted
and send over to the user unencrypted per email.  Of course this makes
some more logic and tables necessary - and a new row for every user also
- but who cares :)  What do you think?

Thanks for your interesting explanation!
Dietrich
Considering you're already jailing access by linking a specific url to a specific password you're making the impact of a hacked password pretty small. Which is a good thing :) I would recommend, if you go this way, to add an expiry date to the url/password combo. So for example you can only use that url/password combo for 3 days before it expires, after that, you need a new combo. Doing it this way (with server-generated passwords) you make sure that _if_ it were ever to fall into hands-it-should-not-be-in, it won't be there for long.

- Tul

P.S. in other words, sounds fine to me :)



--- End Message ---
--- Begin Message ---
2. It's useful if the host company and the client keep the same office hours.

If you have a hosting company with 9 to 5 office hours, you are dead, even if it is next door.

Iv

--- End Message ---
--- Begin Message ---
Hi!.
I need to create a pageflip magazine (you know, a flash magazine).
My client ask me to do a little php program that convert a full pdf magazine into a pageflip magazine. My doubt is: It's possible with php to read a full pdf and make an image for each page?

Thanks a lot.

Ray.

--- End Message ---
--- Begin Message ---
Ray Mckoy wrote:

> Hi!.
> I need to create a pageflip magazine (you know, a flash magazine).
> My client ask me to do a little php program that convert a full pdf
> magazine into a pageflip magazine.
> My doubt is: It's possible with php to read a full pdf and make an
> image for each page?

Dunno, but there are websites that offer this service on demand.  


/Per Jessen, Zürich


--- End Message ---

Reply via email to