Skip to content

Conversation

@gmcodentech
Copy link
Contributor

Hello, I want to add this example in the section of Cryptography. As the 'Argon2' is a powerful and popular algorithms, I think adding this would be really helpful for all zig learners.

@gmcodentech
Copy link
Contributor Author

@jiacai2050, could you please review and help me fix these failing checks. Thank you

@jiacai2050
Copy link
Member

/Users/runner/work/_temp/361a268d-a7af-421e-b2e4-61d09d2f6c10/zig-aarch64-macos-0.14.1/lib/std/start.zig:647:46: error: root source file struct '02-03' has no member named 'main'
    const ReturnType = @typeInfo(@TypeOf(root.main)).@"fn".return_type.?;
                                         ~~~~^~~~~
assets/src/02-03.zig:1:1: note: struct declared here
const std = @import("std");
^~~~~

The logs already tell you what went wrong: https://github.com/zigcc/zig-cookbook/actions/runs/17290154717/job/49075399319?pr=113

You need to define a main method.

@@ -0,0 +1,14 @@
---
.title = "Argon2 Password Hash",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to update the toc.md file to include this recipe.

@gmcodentech
Copy link
Contributor Author

Hi, I think it is good now to proceed to be merged. Thank you

---
Argon2 Password Hash

This Zig program derives a cryptographic key from a password and salt using the Argon2id password hashing algorithm. It uses [std.crypto.pwhash.argon2] to hash a salted password, where the salt is generated using [std.rand.DefaultPrng] to ensure randomness.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The salt is hardcoded, not generated.

Copy link
Contributor Author

@gmcodentech gmcodentech Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is purposely hardcoded for testing using testing.expectEqualStrings. May be, I should update the description in 'src/en-US/02-03-argon2.smd' file stating the same. (hardcoded for unit testing)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need that test, we can just print the hashed password

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will make this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done

gmcodentech and others added 2 commits August 28, 2025 18:15
.author = "gmcodentech",
.layout = "section.shtml",
---
Argon2 Password Hash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected these lines. Please let me know if any particular line should be deleted. Thanks again!

@jiacai2050 jiacai2050 merged commit b827821 into zigcc:main Aug 28, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants