Re: Concatenating a Hash to a String

2020-12-01 Thread Ivan "Rambius" Ivanov
Hello, Thank you all for your help. On Tue, Dec 1, 2020 at 1:38 PM MRAB wrote: > The bytes are all in the ASCII range, so you can convert it into a > string using .decode('ascii'). I utilized encode and decode string methods to convert from bytes to strings > And, of course, use parametrised qu

Re: Concatenating a Hash to a String

2020-12-01 Thread MRAB
On 2020-12-01 05:32, Ivan "Rambius" Ivanov wrote: Hello, I want to store the hashes of strings in a database and I have problems generating the sql statements. I generate the hashes using hashlib and then convert it to base64 and I put the base64 representation in the sql. Here is the code: #!/

Re: Concatenating a Hash to a String

2020-12-01 Thread Dieter Maurer
"Ivan \"Rambius\" Ivanov" wrote at 2020-12-1 00:32 -0500: > ... >This code throws > >$ ./hashinstr.py >Traceback (most recent call last): > File "./hashinstr.py", line 16, in >gen_sql(s) > File "./hashinstr.py", line 13, in gen_sql >sql = "insert into HASHES value ('" + ehash + "')" >Typ

Re: Concatenating a Hash to a String

2020-11-30 Thread Chris Angelico
On Tue, Dec 1, 2020 at 4:53 PM Ivan "Rambius" Ivanov wrote: > > On Tue, Dec 1, 2020 at 12:39 AM Chris Angelico wrote: > > Don't do this! DO NOT do this! Even if it might happen to work with a > > base 64 encoded value, this is a terrible terrible bug just waiting to > > happen. Instead, use *para

Re: Concatenating a Hash to a String

2020-11-30 Thread Ivan "Rambius" Ivanov
On Tue, Dec 1, 2020 at 12:39 AM Chris Angelico wrote: > Don't do this! DO NOT do this! Even if it might happen to work with a > base 64 encoded value, this is a terrible terrible bug just waiting to > happen. Instead, use *parameterized queries* and keep your SQL safe. OK. What are parameterized

Re: Concatenating a Hash to a String

2020-11-30 Thread Chris Angelico
On Tue, Dec 1, 2020 at 4:34 PM Ivan "Rambius" Ivanov wrote: > > Hello, > > I want to store the hashes of strings in a database and I have > problems generating the sql statements. I generate the hashes using > hashlib and then convert it to base64 and I put the base64 > representation in the sql.

Concatenating a Hash to a String

2020-11-30 Thread Ivan "Rambius" Ivanov
Hello, I want to store the hashes of strings in a database and I have problems generating the sql statements. I generate the hashes using hashlib and then convert it to base64 and I put the base64 representation in the sql. Here is the code: #!/usr/bin/env python3.8 import base64 import hashlib