Go Engineer System Course 005 [Learning Notes]

For microservice development, create a microservice project where all project microservices will reside. Create `joyshop_srv`. We need to create user login and registration services, so we will create another directory `user_srv` under the project directory, along with `user_srv/global` (for global object creation and initialization), `user_srv/handler` (for business logic code), `user_srv/model` (for user-related models), `user_srv/pro...`

Microservice Development

Create a microservice project. All project microservices will reside within this project. Create joyshop_srv. Since we are not creating a user login and registration service, we will create another directory under the project directory:
user_srv and user_srv/global (global object creation and initialization)
user_srv/handler (business logic code)
user_srv/model (user-related models)
user_srv/proto (user-related models)
main.go service startup file

We use MD5 encryption for passwords.

1. Message Digest Algorithm 5 (MD5) Information Digest Algorithm

MD5 is a common hashing algorithm with the following main characteristics:

  1. Compressibility
    For data of any length, the calculated MD5 value will always have a fixed length.
  2. Ease of Computation
    It is very easy to compute the MD5 value from the original data.
  3. Modification Resistance
    Any modification to the original data, even a single byte, will result in a significantly different MD5 value.
  4. Strong Collision Resistance
    It is extremely difficult to find two different pieces of data that produce the same MD5 value.
  5. Irreversibility
    It is irreversible; the original data cannot be recovered from an MD5 value.

MD5 Salt Encryption

1. Purpose of Salting

To enhance the security of MD5 encryption and prevent rainbow table attacks, a "salt" value is typically added to the original data before MD5 encryption.

2. Salting Methods

  1. Combine by generating a random number and an MD5-generated string
  2. Concatenate the randomly generated salt value with the original password before performing MD5 encryption.
  3. E.g.: md5( password + salt )
  4. Store both MD5 value and salt value in the database
  5. During registration: Generate a salt, compute the salted MD5, and store both in the database.
  6. During verification: Retrieve the salt, re-encrypt, and compare the MD5 values.
// 设置加密参数
options := &password.Options{
 SaltLen:      16,
 Iterations:   100,
 KeyLen:       32,
 HashFunction: sha512.New,
}

// 1. 加密
salt, encodedPwd := password.Encode("your_password", options)
final := fmt.Sprintf("$pbkdf2-sha512$%s$%s", salt, encodedPwd)

// 2. 拆分(模拟从数据库读取)
parts := strings.Split(final, "$")
saltFromDb := parts[2]
hashFromDb := parts[3]

// 3. 验证
ok := password.Verify("your_password", saltFromDb, hashFromDb, options)
fmt.Println("验证是否通过:", ok)

主题测试文章,只做测试使用。发布者:Walker,转转请注明出处:https://walker-learn.xyz/archives/4779

(0)
Walker的头像Walker
上一篇 Mar 7, 2026 17:00
下一篇 Mar 7, 2026 15:00

Related Posts

  • Deep Dive into ES6 010 [Study Notes]

    Improved array functionality. The peculiar behavior of `new Array()`: when a single numeric value is passed to the constructor, the array's `length` property is set to that value; if multiple values are passed, regardless of whether they are numeric or not, they all become elements of the array. This behavior is confusing, as it's not always possible to pay attention to the type of data passed in, thus posing a certain risk. `Array.of()`, regardless of how many arguments are passed, has no special case for a single numeric value (one argument and numeric type); it always returns an array containing all arguments...

    Personal Mar 8, 2025
    1.3K00
  • Go Engineer Training Course 018 [Learning Notes]

    Getting Started with API Gateway and Continuous Deployment (Kong & Jenkins) corresponds to the course materials "Chapter 2: Getting Started with Jenkins" and "Chapter 3: Deploying Services with Jenkins", outlining the practical path for Kong and Jenkins in enterprise-level continuous delivery. Even with zero prior experience, you can follow the steps to build your own gateway + continuous deployment pipeline. Pre-class Introduction: What is an API Gateway? An API Gateway sits between clients and backend microservices...

    Personal Nov 25, 2025
    28600
  • Love sports, challenge limits, embrace nature.

    Passion. In this fast-paced era, we are surrounded by the pressures of work and life, often neglecting our body's needs. However, exercise is not just a way to keep fit; it's a lifestyle that allows us to unleash ourselves, challenge our limits, and dance with nature. Whether it's skiing, rock climbing, surfing, or running, cycling, yoga, every sport allows us to find our inner passion and feel the vibrancy of life. Sport is a self-challenge. Challenging limits is not exclusive to professional athletes; it's a goal that everyone who loves sports can pursue. It can...

    Personal Feb 26, 2025
    1.5K00
  • TS Everest 001 [Study Notes]

    Course Outline: Set up a TypeScript development environment. Master TypeScript's basic, union, and intersection types. Understand the purpose and usage of type assertions in detail. Master type declaration methods for functions and classes in TypeScript. Master the purpose and definition of type aliases and interfaces. Master the application scenarios of generics and apply them proficiently. Flexibly apply conditional types, mapped types, and built-in types. Create and use custom types. Understand the concepts of namespaces and modules, and how to use...

    Personal Mar 27, 2025
    1.6K00
  • Go Engineer Comprehensive Course: protoc-gen-validate Study Notes

    protoc-gen-validate: Introduction and Usage Guide ✅ What is protoc-gen-validate? protoc-gen-validate (PGV for short) is a Protocol Buffers plugin used to add validation logic for struct fields in generated Go code. It automatically generates validation code for each field by adding validation rules in .proto files, saving you the trouble of manually...

    Personal Nov 25, 2025
    1.4K00
EN
简体中文 繁體中文 English