Added new method in utils for hashing
This commit is contained in:
		
							parent
							
								
									6bba159e64
								
							
						
					
					
						commit
						7abe33ecaa
					
				@ -9,7 +9,6 @@ const utils = @import("../utils.zig");
 | 
			
		||||
//TODO move these to env variables
 | 
			
		||||
 | 
			
		||||
const key = "aGVyZUlzQUdpYmVyaXNoS2V5ISE=";
 | 
			
		||||
pub const HASH_SEED: u64 = 6065983110;
 | 
			
		||||
 | 
			
		||||
pub const VerifyAuthError = error{
 | 
			
		||||
    Unauthorized,
 | 
			
		||||
 | 
			
		||||
@ -42,7 +42,7 @@ pub fn login(req: *httpz.Request, res: *httpz.Response) !void {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var user: ?models.User = null;
 | 
			
		||||
    const password_hash = @truncate(u32, std.hash.Wyhash.hash(auth.HASH_SEED, body.password));
 | 
			
		||||
    const password_hash = utils.hashPassword(body.password);
 | 
			
		||||
    if (body.username != null) {
 | 
			
		||||
        const query =
 | 
			
		||||
            "WHERE pass_hash = ? and username = ?;";
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,7 @@
 | 
			
		||||
const std = @import("std");
 | 
			
		||||
 | 
			
		||||
const HASH_SEED: u64 = 6065983110;
 | 
			
		||||
 | 
			
		||||
fn SpreadResult(comptime Base: type, comptime Additional: type) type {
 | 
			
		||||
    comptime {
 | 
			
		||||
        // const type_info = @typeInfo(Base);
 | 
			
		||||
@ -123,6 +125,11 @@ pub fn generateRandomString(allocator: std.mem.Allocator) ![]const u8 {
 | 
			
		||||
    return code;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn hashPassword(password: []const u8) u32 {
 | 
			
		||||
    const password_hash = @truncate(u32, std.hash.Wyhash.hash(HASH_SEED, password));
 | 
			
		||||
    return password_hash;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
test {
 | 
			
		||||
    // const vote = .{ .id = 0, .createdAt = "DATE" };
 | 
			
		||||
    // const data = structConcatFields(vote, .{ .id2 = vote.id });
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user