|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On March 01 2015 05:32 Manit0u wrote:Show nested quote +On March 01 2015 05:14 teamamerica wrote: They have a few different components - salt, iv, and actual passphrase used to generate key. I'm wondering how important it is to keep all of that data private. I was going to simply hardcode salt into code(choose 8 random bytes), and also store the IV with the encrypted text.
http://security.stackexchange.com/questions/17421/how-to-store-saltThe chosen answer is very informational and a good read in itself. Also, it's important to have a unique salt for each encryption, rather than having a single global salt.
Hi, thanks for posting that. However - and maybe because that is only focusing on storing password (so only 1 way transformation needed), it doesn't discus storing an IV, which is used by the actual symmetric crypto part of storage (from what I understand of my code -- passphrase => key (using KDF), cleartext => key => ciphertext.
From what I've googled, IV can be stored in cleartext to (they compare it to storing salt for hash, here I guess we have both because we use both kdf and aes).
Wondering if anyone had other exp - also - beyond that, anything glaringly wrong with my code?
I guess I shouldn't hard code the salt but honestly does it make a difference? This isn't an online application where adversary is sending me queries and I'm responding.
edit: in response to your edit "Also, it's important to have a unique salt for each encryption, rather than having a single global salt."
I only use salt to generate one thing - the key. So really, there is only one encryption going on that uses it I guess. Unless I'm not following something?
|
the this keyword is a pointer to the object on which a member function is called. in your example member function being called is character::character(), and the type of this is character*.
when you apply the dereference operator * on a pointer, you obtain an l-value of the object that is pointed to. in your example the type of the result of dereferencing this (aka when you write *this) is character&.
addObjectToList takes an argument of type character*, thus you need to pass this and not *this.
illustration:
type* pointer_to_object = new type(); type* another_pointer_object = pointer; type& reference_to_objeft = *pointer; type copy_of_object=*pointer;
|
On March 01 2015 05:36 sabas123 wrote:+ Show Spoiler + class character; std::vector<characater>objectList;
class character{ character(); };
character::character(){ addObjectToList(*this); }
addObjectToList(character *obj){ objectList.push_back( character *obj); }
error:: expecting primal type before '*'
sorry about my terrible post, I hope this clears some stuff up.
Lots of errors in the code there, make sure you use code tags too next time to keep the formatting.
keyword this is a pointer to the current instance of the object *this dereferences that pointer to the actual instance your addObjectToList method takes in a character*, but you pass in a dereferenced this, or the actual object you have a syntax error with push_back( character *obj), which doesn't make sense since you don't need to specify the type there again (the type is already known by the method definition) the addObjectToList definition is below its first usage, and you haven't forward declared it earlier, so it wouldn't compile your character constructor was declared private, you need to set it as public
may be more that i missed and i dont know if my code compiles
class character; std::vector<character> objectList;
class character{ public: character(); };
addObjectToList(character obj){ objectList.push_back(obj); }
character::character() { addObjectToList(*this); }
|
i was assuming he wanted to store pointers to instantiations, and not copies of instantiations.
|
oo didn't see that earlier post
class character; std::vector<character*> objectList;
class character{ public: character(); };
addObjectToList(character* obj){ objectList.push_back(obj); }
character::character() { addObjectToList(this); }
|
On March 01 2015 17:05 Blisse wrote:oo didn't see that earlier post
class character; std::vector<character*> objectList;
class character{ public: character(); };
addObjectToList(character* obj){ objectList.push_back(obj); }
character::character() { addObjectToList(this); }
90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=
the result of alot of face keyboarding over this code.
thanks alot!
btw you forgot to add a pointer too bjectList.push_back(obj);
|
On March 02 2015 02:24 sabas123 wrote:Show nested quote +On March 01 2015 17:05 Blisse wrote:oo didn't see that earlier post
class character; std::vector<character*> objectList;
class character{ public: character(); };
addObjectToList(character* obj){ objectList.push_back(obj); }
character::character() { addObjectToList(this); }
90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[= the result of alot of face keyboarding over this code. thanks alot! btw you forgot to add a pointer too bjectList.push_back(obj);
'obj' is a pointer.
|
On March 02 2015 03:53 Khalum wrote:Show nested quote +On March 02 2015 02:24 sabas123 wrote:On March 01 2015 17:05 Blisse wrote:oo didn't see that earlier post
class character; std::vector<character*> objectList;
class character{ public: character(); };
addObjectToList(character* obj){ objectList.push_back(obj); }
character::character() { addObjectToList(this); }
90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[=90p;0p;-0p;-[=0p;-[= the result of alot of face keyboarding over this code. thanks alot! btw you forgot to add a pointer to objectList.push_back(obj); 'obj' is a pointer. I had to place an * before the obj in the push_back call otherwise it would wouldn't compile for me.
|
That can't be right if it's code like what's in Blisse's post.
|
On March 02 2015 04:47 sabas123 wrote:Show nested quote +On March 02 2015 03:53 Khalum wrote: [..] btw you forgot to add a pointer to objectList.push_back(obj);
'obj' is a pointer. I had to place an * before the obj in the push_back call otherwise it would wouldn't compile for me.
You probably have a vector< character > instead of a vector< character* > ?
|
blasphemous spaces inside the template typename!
make sure you know what's the difference between vector<character*> and vector<character>, and why you're probably talking about using the first one and not the second. nunez has a bit more thorough explanation of what was going wrong up above.
|
I am starting to discover that very good programmers must also have very very good organizational skills
|
On March 02 2015 13:36 travis wrote: I am starting to discover that very good programmers must also have very very good organizational skills Perhaps you have uncovered why I am not the best programmer!
Even more important is patience I think. In programming you may end up spending a lot of time doing (Seemingly) very little.
|
On March 02 2015 13:47 meatpudding wrote:Show nested quote +On March 02 2015 13:36 travis wrote: I am starting to discover that very good programmers must also have very very good organizational skills Perhaps you have uncovered why I am not the best programmer! Even more important is patience I think. In programming you may end up spending a lot of time doing (Seemingly) very little.
Well, even in the preface of Clean Code they mention that programming is mostly reading and writing, but the reading to writing ratio is roughly 10 to 1. Go figure.
|
spent 3 hours fixing my sass to realize that foundation was being imported after my custom styles, so it would keep overwriting my custom stuff and making me really annoyed that nothing i changed was showing up...
|
On March 02 2015 05:15 Khalum wrote:Show nested quote +On March 02 2015 04:47 sabas123 wrote:On March 02 2015 03:53 Khalum wrote: [..] btw you forgot to add a pointer to objectList.push_back(obj);
'obj' is a pointer. I had to place an * before the obj in the push_back call otherwise it would wouldn't compile for me. You probably have a vector< character > instead of a vector< character* > ? your right, thanks for pointing it out
|
I so hate ugly code...
Before:
protected function generatePassword($length = 12) { $lowercase = "qwertyuiopasdfghjklzxcvbnm"; $uppercase = "ASDFGHJKLZXCVBNMQWERTYUIOP"; $numbers = "1234567890"; $specialCharacters = "_!?"; $randomCode = ""; mt_srand(crc32(microtime())); $max = strlen($lowercase) - 1; for ($x = 0; $x < abs($length / 3); $x++) { $randomCode .= $lowercase{mt_rand(0, $max)}; } $max = strlen($uppercase) - 1; for ($x = 0; $x < abs($length / 3); $x++) { $randomCode .= $uppercase{mt_rand(0, $max)}; } $max = strlen($specialCharacters) - 1; for ($x = 0; $x < abs($length / 3); $x++) { $randomCode .= $specialCharacters{mt_rand(0, $max)}; } $max = strlen($numbers) - 1; for ($x = 0; $x < abs($length / 3); $x++) { $randomCode .= $numbers{mt_rand(0, $max)}; }
return str_shuffle($randomCode); }
After:
protected function generatePassword($length = 12) { $lowercaseLettersArray = range('a', 'z'); $uppercaseLettersArray = range('A', 'Z'); $numbersArray = range(0, 9); $specialCharactersArray = array('_', '!', '?'); $randomizedString = '';
$i = abs($length / 3);
while ($i--) { $randomizedString .= $this->getRandomArrayMember($lowercaseLettersArray); $randomizedString .= $this->getRandomArrayMember($uppercaseLettersArray); $randomizedString .= $this->getRandomArrayMember($numbersArray); $randomizedString .= $this->getRandomArrayMember($specialCharactersArray); }
return str_shuffle($randomizedString); }
protected function getRandomArrayMember($array) { return $array[array_rand($array)]; }
Edit: Unrelated bonus good read: http://apievangelist.com/2012/01/12/the-secret-to-amazons-success-internal-apis/
|
On March 02 2015 20:09 Manit0u wrote:I so hate ugly code... Before: protected function generatePassword($length = 12) { $lowercase = "qwertyuiopasdfghjklzxcvbnm"; $uppercase = "ASDFGHJKLZXCVBNMQWERTYUIOP"; $numbers = "1234567890"; $specialCharacters = "_!?"; $randomCode = ""; mt_srand(crc32(microtime())); $max = strlen($lowercase) - 1; for ($x = 0; $x < abs($length / 3); $x++) { $randomCode .= $lowercase{mt_rand(0, $max)}; } $max = strlen($uppercase) - 1; for ($x = 0; $x < abs($length / 3); $x++) { $randomCode .= $uppercase{mt_rand(0, $max)}; } $max = strlen($specialCharacters) - 1; for ($x = 0; $x < abs($length / 3); $x++) { $randomCode .= $specialCharacters{mt_rand(0, $max)}; } $max = strlen($numbers) - 1; for ($x = 0; $x < abs($length / 3); $x++) { $randomCode .= $numbers{mt_rand(0, $max)}; }
return str_shuffle($randomCode); }
After: protected function generatePassword($length = 12) { $lowercaseLettersArray = range('a', 'z'); $uppercaseLettersArray = range('A', 'Z'); $numbersArray = range(0, 9); $specialCharactersArray = array('_', '!', '?'); $randomizedString = '';
$i = abs($length / 3);
while ($i--) { $randomizedString .= $this->getRandomArrayMember($lowercaseLettersArray); $randomizedString .= $this->getRandomArrayMember($uppercaseLettersArray); $randomizedString .= $this->getRandomArrayMember($numbersArray); $randomizedString .= $this->getRandomArrayMember($specialCharactersArray); }
return str_shuffle($randomizedString); }
protected function getRandomArrayMember($array) { return $array[array_rand($array)]; }
I hope this is only generating passwords of length 4, 8, and 12
|
Well, the length variable is deceiving in this case because if length = 12 the generated password will have 16 characters...
|
On March 02 2015 20:47 Manit0u wrote: Well, the length variable is deceiving in this case because if length = 12 the generated password will have 16 characters...
Right, my math started to suck at 12 ... anyways, beautiful code isn't just refactored well.. it also makes sense. I'm not sure that totally makes sense. Karma for being a smart ass, I'll rationalize as "2/3 ain't bad".
|
|
|
|