-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add library to securely hash passwords (like bcrypt) #2744
Add library to securely hash passwords (like bcrypt) #2744
Comments
Related issue: #2441 |
@daneshk can we address this? |
Hello, I just wanted to ask if it is a beginner-friendly task to be done. I am pretty excited about such contributions but I just can't make my mind if am ready enough, could you please help me out like what amount of knowledge of Ballerina is just enough to get this working? Thanks! |
👋 Welcome, @HamzaMateen ! 🚀 We're thrilled to have you join the Ballerina Lang community! Whether you're a seasoned developer or just starting your journey with Ballerina, we value your contributions and look forward to collaborating with you.
Remember, no contribution is too small, and your feedback is invaluable. Feel free to ask questions, propose ideas, or report issues. Together, we can make Ballerina even better! |
Hello @HamzaMateen, This issue proposes the addition of a fresh API within the Ballerina Crypto package for password hashing using BCrypt. So you need to come up with a new API design(you need to state what is the API function name that you are going to introduce, what are the input parameters, and what would be the returning data type) that helps to support the above-mentioned requirement. It would be easier for you to use a Java Bcrypt library to implement this by calling its functions in the Ballerina code. You can refer to how to call Java functions using Ballerina here. |
This is wonderful! |
Okay so I tried building the ballerina-distribution, which I was able to build successfully but I encountered the following error during the execution phase after running the command: > ./gradlew clean build -x test
I am unsure but how I should upgrade the gradle version. PS. I have read up on Java and the Ballerina Interop mechanism and am ready to start creating my API for BCrypt, but this project build is slowing me down. Your help will be appreciated! Thanks |
Hello @HamzaMateen You can start this by building the crypto module rather than building the entire ballerina distribution. To test the solution you can simply add a test case in the test folder and run the build command( |
For any future reader: When using Bouncy Castle's Or depending on the use case, you could use (Or use the bcrypt implementation from another library.) |
Can I please work on this issue? |
Hi @Riyan-Mo I have assigned the issue to you.
|
@keizer619 Thank you for assigning me this issue. I will gladly use the resources. |
@Riyan-Mo Are you still working on this? If not we can open this for others |
@keizer619 Please unassign me and open this issue to others. |
Hi, |
@randilt Could you update the proposed new API here please. We need to keep update the issue with the new API design. |
Password Hashing API for Ballerina Crypto ModuleNew password hashing API in the BCryptImplements the BCrypt password hashing algorithm based on the Blowfish cipher. public isolated function hashBcrypt(string password, int workFactor = 12) returns string|Error Parameters:
public isolated function verifyBcrypt(string password, string hashedPassword) returns boolean|Error Example: string password = "your-password";
// Hash with default work factor (12)
string hashedPassword1 = check crypto:hashBcrypt(password);
// Hash with custom work factor
string hashedPassword2 = check crypto:hashBcrypt(password, 14);
boolean isValid = check crypto:verifyBcrypt(password, hashedPassword1); Argon2Implements the Argon2id variant of the Argon2 password hashing algorithm, optimized for both high memory usage and GPU resistance. public isolated function hashArgon2(string password, int iterations = 3,
int memory = 65536, int parallelism = 4) returns string|Error Parameters:
Output hash length is fixed at 256 bits for optimal security and performance. public isolated function verifyArgon2(string password, string hashedPassword) returns boolean|Error Example: string password = "your-password";
// Hash with default parameters
string hashedPassword1 = check crypto:hashArgon2(password);
// Hash with custom parameters
string hashedPassword2 = check crypto:hashArgon2(password, 4, 131072, 8);
boolean isValid = check crypto:verifyArgon2(password, hashedPassword1); |
Description:
Right now, when we want to handle passwords in a Ballerina service, there's no inbuilt option that uses salt/pepper. Hashing passwords using a pure hash function (like SHA512, SHA 256) is not recommended due to hashes of 2 users having the same password will look exactly the same and is a security risk.
Therefore, we need to implement an algorithm like
bcrypt
(https://www.baeldung.com/spring-security-registration-password-encoding-bcrypt#define-the-password-encoder) into the cryto module.Describe your problem(s)
I was implementing a REST API to power a React.js based web app and when I wanted to handle user registrations, there was no option to securely hash user passwords.
Describe your solution(s)
Need to implement one or more secure password hashing algorithms (like bcrypt) into the crypto module.
The text was updated successfully, but these errors were encountered: