Strange errors with SPOD and binary data

29 views
Skip to first unread message

Nathan Hüsken

unread,
Aug 19, 2015, 8:09:21 AM8/19/15
to haxe...@googlegroups.com

Hey,

I have a mysql table, with a definition like this:

@:table("providers")
class Provider extends sys.db.Object {
  public var id : SId;
  public var username : SString<32>;
  public var passwordhash : SBytes<32>;
  public var passwordsalt : SBytes<32>;
  public var accountenabled : SBool;
}

Now, when I insert into the table (with salt randomly generated and hashedPassword based on it):

    var provider = new datamodel.Provider();
    provider.username = providerUsername;   //String
    provider.passwordhash = hashedPassword;//Bytes
    provider.passwordsalt = salt;                       //Bytes
    provider.accountenabled = false;                //Bool
    provider.insert();

I sometimes (not always!) get this error:

Error: Error while executing INSERT INTO providers (username,passwordhash,passwordsalt,accountenabled) VALUES ('stopsack_012', '~�a� K  2� �O��z��\r��e� 1{�Z�c��', x'30c7f2dedaad815a5a7f752734895600c725618e18cdefdaa0fccb4a72fc8585 ', 0)

First thing I am noticing: Why is passwordhash encoded differently than passwordsalt?

As I said, this error does not alway occure, only sometimes.
Ideas?

Thanks!
Nathan

Nathan Hüsken

unread,
Aug 19, 2015, 8:13:06 AM8/19/15
to haxe...@googlegroups.com

Trying to reproduce the problem by hand it seems that the addition space (“ “) at the end of the

 x'30c7f2dedaad815a5a7f752734895600c725618e18cdefdaa0fccb4a72fc8585 '

value seems to be the problem. Is this a bug? Why is it there …

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Nathan Hüsken

unread,
Aug 19, 2015, 8:18:41 AM8/19/15
to haxe...@googlegroups.com
I should mention, I am targeting php!

Nathan Hüsken

unread,
Aug 19, 2015, 8:33:56 AM8/19/15
to haxe...@googlegroups.com

Ok, I kind of found the cause. But I do not really what I am doing, so I need some confirmation :-).

The function

    function base16_encode(str : String) {
        str = untyped __call__("unpack", "H"+(2 * str.length), str);
        str = untyped __call__("chunk_split", untyped str[1]);
        return str;
    }

in std/php/db/PDO.hx seems to be the problem. The

        str = untyped __call__("chunk_split", untyped str[1]);

adds a “\r\n” to the string (see here). Replacing the line with:

    str = untyped str[1];

solves the problem. But I have no Idea if I am doing something wrong here …

Thanks,
Nathan

Nathan Hüsken

unread,
Aug 19, 2015, 8:42:18 AM8/19/15
to haxe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages