【WEEK6】 【DAY7】MD5 Encryption Transactions【English Version】

2024.4.7 Sunday
Following the previous article 【WEEK6】 【DAY3】MySQL Functions【English Version】

Contents

    • 5.3. MD5 Encryption
      • 5.3.1. Introduction
      • 5.3.2. Testing MD5 Encryption
        • 5.3.2.1. Plain Text Passwords
        • 5.3.2.2. Implementing Data Encryption
        • 5.3.2.3. Encryption for ID 1
        • 5.3.2.4. Encrypt All Passwords
        • 5.3.2.5. Encryption Upon Insertion
        • 5.3.2.6. Verifying Encrypted Statements
    • 5.4. Summary
  • 6. Transactions and Indexes
    • 6.1. What is a Transaction
    • 6.2. The ACID Principles of Transactions
      • 6.2.1. Atomicity
      • 6.2.2. Consistency: Eventual Consistency (Conservation of Energy)
      • 6.2.3. Isolation
      • 6.2.4.Durability
      • 6.2.5. Problems Caused by Isolation
    • 6.3. Basic Syntax
    • 6.4. Simulated Scenario
      • 6.4.1. Create Table, Insert Data
      • 6.4.2. Simulate Transfer

5.3. MD5 Encryption

5.3.1. Introduction

MD5, standing for Message-Digest Algorithm 5, is used to ensure information transmission is complete and consistent. It is one of the widely used cryptographic hash functions in computing (also known as digest algorithms or hash algorithms), with mainstream programming languages commonly having MD5 implementations. It operates data (such as Chinese characters) to another fixed-length value, which is the basic principle of hash functions. MD5 has predecessors including MD2, MD3, and MD4.
Irreversible.

5.3.2. Testing MD5 Encryption

(Create a table first)

-- MD5 --
-- Testing MD5 Encryption
CREATE TABLE `testmd5`(
	`id` INT(4) NOT NULL,
	`name` VARCHAR(20) NOT NULL,
	`pwd` VARCHAR(50) NOT NULL,
	PRIMARY KEY(`id`)
)ENGINE = INNODB DEFAULT CHARSET = utf8

Insert image description here

5.3.2.1. Plain Text Passwords
-- Plain Text Passwords
INSERT INTO testmd5 VALUES (1, 'ZHANGSAN', '123456'),(2, 'LISI', '123456'),(3, 'WANGWU', '123456')

Insert image description here

5.3.2.2. Implementing Data Encryption
5.3.2.3. Encryption for ID 1
-- Encryption
UPDATE testmd5 SET pwd = MD5(pwd) WHERE id = 1

Insert image description here

5.3.2.4. Encrypt All Passwords
-- Encrypt All Passwords
UPDATE testmd5 SET pwd = MD5(pwd)

Insert image description here

5.3.2.5. Encryption Upon Insertion
-- Encryption Upon Insertion
INSERT INTO testmd5 VALUES (4, 'xiaoming', MD5('123456'))

Insert image description here

5.3.2.6. Verifying Encrypted Statements
-- How to verify: Encrypt the password provided by the user with MD5, then compare it with the encrypted value (when the same value is encrypted the same number of times, the resulting encryption result is exactly the same)
SELECT * FROM testmd5 WHERE `name` = 'xiaoming' AND pwd = MD5('123456')

Insert image description here

5.4. Summary

Insert image description here

 -- ================ Built-in Functions ================
 -- Numeric Functions
 abs(x)            -- Absolute value abs(-10.9) = 10
 format(x, d)    -- Format number with thousand separator format(1234567.456, 2) = 1,234,567.46
 ceil(x)            -- Round up ceil(10.1) = 11
 floor(x)        -- Round down floor(10.1) = 10
 round(x)        -- Round to the nearest integer
 mod(m, n)        -- m%n m mod n Remainder 10%3=1
 pi()            -- Get pi
 pow(m, n)        -- m^n
 sqrt(x)            -- Square root
 rand()            -- Random number
 truncate(x, d)    -- Truncate to d decimal places
 
 -- Date and Time Functions
 now(), current_timestamp();     -- Current date and time
 current_date();                    -- Current date
 current_time();                    -- Current time
 date('yyyy-mm-dd hh:ii:ss');    -- Get the date part
 time('yyyy-mm-dd hh:ii:ss');    -- Get the time part
 date_format('yyyy-mm-dd hh:ii:ss', '%d %y %a %d %m %b %j');    -- Format date
 unix_timestamp();                -- Get Unix timestamp
 from_unixtime();                -- Convert timestamp to date
 
 -- String Functions
 length(string)            -- Length of string in bytes
 char_length(string)        -- Number of characters in string
 substring(str, position [,length])        -- Substring of str starting at position for length characters
 replace(str, search_str, replace_str)    -- Replace search_str with replace_str in str
 instr(string, substring)    -- Position of the first occurrence of substring in string
 concat(string [,...])    -- Concatenate strings
 charset(str)            -- Character set of string
 lcase(string)            -- Convert to lowercase
 left(string, length)    -- Take length characters from the left of string
 load_file(file_name)    -- Load content from a file
 locate(substring, string [,start_position])    -- Similar to instr, but can specify start position
 lpad(string, length, pad)    -- Pad string on the left with pad until length is reached
 ltrim(string)            -- Trim leading spaces
 repeat(string, count)    -- Repeat string count times
 rpad(string, length, pad)    -- Pad string on the right with pad until length is reached
 rtrim(string)            -- Trim trailing spaces
 strcmp(string1, string2)    -- Compare two strings character by character
 
 -- Aggregate Functions
 count()
 sum();
 max();
 min();
 avg();
 group_concat()
 
 -- Other Common Functions
 md5();
 default();

6. Transactions and Indexes

6.1. What is a Transaction

6.1.1. A transaction is a group of SQL statements that are executed together.
6.1.2. If one SQL statement within the group fails, all SQL statements in that batch are cancelled.
6.1.3. MySQL transaction processing only supports the InnoDB and BDB table types.

6.2. The ACID Principles of Transactions

https://www.jianshu.com/p/133d8b798271

6.2.1. Atomicity

All operations within the entire transaction either complete fully or are completely undone. They do not stop at any intermediate point. If an error occurs during the execution of the transaction, it will be rolled back to the state before the transaction started, as if the transaction had never been executed.

6.2.2. Consistency: Eventual Consistency (Conservation of Energy)

A transaction can encapsulate state changes (unless it is read-only). The system must always remain consistent, no matter how many concurrent transactions there are at any given time. That is, even if there are multiple concurrent transactions, the system must operate as if transactions were serial. Its main features are protectiveness and invariance, using the transfer example, assume there are five accounts, each with a balance of 100 units, then the total of the five accounts is 500 units. If multiple transfers occur among these 5 accounts at the same time, no matter how many concurrent ones, for example, transferring 5 units between A and B, 10 units between C and D, and 15 units between B and E, the total of the five accounts should still be 500 units. This is protectiveness and invariance.

6.2.3. Isolation

Execute transactions in isolation, making them appear as the only operation in the system at a given time. If there are two transactions, running at the same time, performing the same functions, the isolation of the transactions ensures that each transaction is considered by the system to be the only one using the system. This property is sometimes referred to as serializability. To prevent confusion between transaction operations, requests must be serialized or sequenced so that only one request is made on the same data at the same time.

6.2.4.Durability

After the transaction is completed (committed), the changes made by the transaction to the database are permanently saved in the database and will not be rolled back.

6.2.5. Problems Caused by Isolation

Dirty read: Reading uncommitted data from another transaction.
Non-repeatable reads: Reading a row of data from a table and getting different results at different times within a transaction. (This is not necessarily wrong, just inappropriate in some cases)
Phantom reads: Reading data inserted by another transaction within a transaction, leading to inconsistency in the total amount read before and after. (Usually row-affected, e.g., an additional row)

6.3. Basic Syntax

-- Transactions --
-- MySQL transactions are set to auto-commit by default
SET autocommit = 0	-- Disable
SET autocommit = 1	-- Enable (default)

-- Manually handling transactions (first, disable auto-commit)
SET autocommit = 0

-- Start of transaction
START TRANSACTION	-- Marks the start of a transaction, from this line forward all SQL are in the same transaction
INSERT XX
INSERT XX

-- (If successful) commit: persist changes
COMMIT

-- (If unsuccessful) rollback: revert to original state
ROLLBACK

-- End of transaction (then re-enable auto-commit)
SET autocommit = 1

-- Savepoints
SAVEPOINT savepoint_name	-- Sets a savepoint within a transaction
ROLLBACK TO SAVEPOINT savepoint_name	-- Offers a chance to rollback to a previous savepoint
RELEASE SAVEPOINT savepoint_name	-- Removes a savepoint

Insert image description here

6.4. Simulated Scenario

/*
Class test question

A purchases a product priced at 500 units online, paying via bank transfer.
A's bank card balance is 2000, then pays 500 to merchant B.
Merchant B's initial bank card balance is 10000

Create shop database and account table and insert 2 records
*/

6.4.1. Create Table, Insert Data

#Simulated scenario
-- Transferring funds
CREATE DATABASE shop CHARACTER SET utf8 COLLATE utf8_general_ci
USE shop

CREATE TABLE `account`(
	`id` INT(3) NOT NULL AUTO_INCREMENT,
	`name` VARCHAR(30) NOT NULL,
	`money` DECIMAL(9,2) NOT NULL,
	PRIMARY KEY (`id`)
)ENGINE = INNODB DEFAULT CHARSET = utf8

-- Initialize (insert) relevant data
INSERT INTO account(`name`, `money`)
VALUES ('A', 2000.00),('B', 1000.00)

6.4.2. Simulate Transfer

-- Simulating transfer: Transactions (execute in batches separated by blank lines)
SET autocommit = 0;	-- Disable auto-commit

START TRANSACTION	-- Start a transaction

UPDATE account SET money = money-500 WHERE `name` = 'A';	-- A subtracts 500
UPDATE account SET money = money+500 WHERE `name` = 'B';	-- B adds 500

COMMIT;	-- Commit transaction
ROLLBACK;	-- Rollback (only successful before 'commit transaction' is executed)

SET autocommit = 1; -- Reset to default

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/525022.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

位域与联合体巧妙使用

在编写dbc报文的协议解析时&#xff0c;使用位域运算和联合体的组合&#xff0c;能够巧妙解决字段解析问题&#xff0c;代码看起来整洁又健壮。 #include <algorithm> #include <iostream> #include <vector>using namespace std;typedef union tagCoreCalib…

Python爬虫:为什么你爬取不到网页数据

目录 前言 一、网络请求被拒绝 二、数据是通过JavaScript加载的 三、需要进行登录 四、网站反爬虫策略 五、网站结构变更 总结 前言 作为一名开发者&#xff0c;使用Python编写爬虫程序是一项常见的任务。爬虫程序的目的是收集互联网上的数据&#xff0c;并将其保存或使…

【漏洞复现】用友畅捷通TPlus GetStoreWarehouseByStore .net反序列化漏洞

0x01 阅读须知 “如棠安全的技术文章仅供参考&#xff0c;此文所提供的信息只为网络安全人员对自己所负责的网站、服务器等&#xff08;包括但不限于&#xff09;进行检测或维护参考&#xff0c;未经授权请勿利用文章中的技术资料对任何计算机系统进行入侵操作。利用此文所提供…

【Lavavel框架】——各目录作用的介绍

&#x1f468;‍&#x1f4bb;个人主页&#xff1a;开发者-曼亿点 &#x1f468;‍&#x1f4bb; hallo 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍&#x1f4bb; 本文由 曼亿点 原创 &#x1f468;‍&#x1f4bb; 收录于专栏&#xff1a…

C++ 之 【类与对象】从入门到精通一条龙服务 入门篇

不要觉的自己很没用&#xff0c;其实你还可以给家人带来温暖&#xff0c;比如爸妈看到你就来火 目录&#xff1a; 一、面向过程和面向对象初步认识 二、类的引入 三、类的定义 四、类的访问限定符及封装 1.访问限定符 2.封装 五、类的作用域 六、类的实例化 七、类的…

亚马逊云配置深度学习环境

开发环境 对于MacOS来说没无法cuda&#xff0c;所以用的是mps后端计算&#xff0c;所以也无法打印GPU数量和型号。 torch.backends.mps.is_available()如果使用PopOS的话&#xff0c;可以选择自带英伟达驱动的镜像&#xff0c;这样就可以免去复杂的驱动安装流程。 EC2 (自己…

RabbitMQ的交换机与队列

一、流程 首先先介绍一个简单的一个消息推送到接收的流程&#xff0c;提供一个简单的图 黄色的圈圈就是我们的消息推送服务&#xff0c;将消息推送到 中间方框里面也就是 rabbitMq的服务器&#xff0c;然后经过服务器里面的交换机、队列等各种关系&#xff08;后面会详细讲&am…

计算机毕业设计PHP+vue+mysql外卖订餐配送系统

本系统的设计与实现共包含17个表:分别是关于我们信息表&#xff0c;菜品分类信息表&#xff0c;菜品信息信息表&#xff0c;配置文件信息表&#xff0c;订单信息信息表&#xff0c;菜品信息评论表信息 表&#xff0c;留言反馈信息表&#xff0c;美食资讯信息表&#xff0c;配送…

白色磨砂质感html5页源码

白色磨砂质感html5页源码&#xff0c;简约的基础上加上了团队成员&#xff0c;自动打字特效音乐播放器存活时间 源码下载 https://www.qqmu.com/2980.html

牛客NC93 设计LRU缓存结构【hard 链表,Map Java】

题目 题目链接&#xff1a; https://www.nowcoder.com/practice/5dfded165916435d9defb053c63f1e84 思路 双向链表map最新的数据放头结点&#xff0c;尾节点放最老的数据&#xff0c;没次移除尾巴节点本地考察链表的新增&#xff0c;删除&#xff0c;移动节点参考答案Java im…

K8s学习四(资源调度_1)

资源调度 发现对Pod操作不方便&#xff0c;不能直接操作&#xff0c;而且不能直接编辑&#xff0c;需要对原来的配置文件进行操作&#xff0c;而且需要删除之后再创建Pod&#xff0c;不方便&#xff0c;更多是通过控制器来操作。 Label和Selector 通过设置标签和选择器来确定…

python 06实验

实验目的 &#xff08;1&#xff09;掌握Python流程控制语句&#xff0c;合理使用循环进行程序设计 &#xff08;2&#xff09;掌握Python数据结构&#xff0c;能熟练运用进行程序设计 &#xff08;3&#xff09;掌握Python的文件读写&#xff0c;能编写读取数据集的程序 1…

java理论小作业(2)--类

第一题 1.题目&#xff1a; 2.解析&#xff1a; 首先&#xff0c;我们来分析Hello1类的结构和给定代码的执行流程&#xff1a; Hello1类中有两个成员变量&#xff0c;一个静态的a和一个非静态的b。静态变量a属于类本身&#xff0c;而非静态变量b属于类的每一个实例&#xff…

c++20协程详解(四)

前言 到这就是协程的最后一节了。希望能帮到大家 代码 到这里我们整合下之前二、三节的代码 #include <coroutine> #include <functional> #include <chrono> #include <iostream> #include <thread> #include <mutex> #include <me…

24上教资面试报名时间汇总⏰报名流程✅

24上教资面试报名公告已经发布&#xff01; &#x1f4a1;报名地址&#xff1a;中小学教师资格考试网 &#x1f550;报名时间&#xff1a;4月12日开始 广东&#xff1a;4月12日10:00-15日17:00 河北&#xff1a;4月12日10:00至4月15日17:00 广西&#xff1a;4月12日10:00至15日…

深入理解Vue 3.0中的watch属性immediate和deep的用法

摘要&#xff1a; 在 Vue 3.0 中&#xff0c;watch 是一个用于观察和响应组件中数据变化的强大工具。它允许我们监听组件中的属性、对象或数组的变化&#xff0c;并执行相应的回调函数。除了基本的用法外&#xff0c;watch 还提供了两个扩展选项&#xff1a;immediate 和 deep…

【JavaScript】原型链/作用域/this指针/闭包

1.原型链 参考资料&#xff1a;Annotated ES5 ECMAScript起初并不支持如C、Smalltalk 或 Java 中“类”的形式创建对象&#xff0c;而是通过字面量表示法或者构造函数创建对象。每个构造函数都是一个具有名为“prototype”的属性的函数&#xff0c;该属性用于实现基于原型的继…

【氮化镓】在轨实验研究辐射对GaN器件的影响

【Pioneering evaluation of GaN transistors in geostationary satellites】 摘要&#xff1a; 这篇论文介绍了一项为期6年的空间实验结果&#xff0c;该实验研究了在地球静止轨道上辐射对氮化镓&#xff08;GaN&#xff09;电子元件的影响。实验使用了四个GaN晶体管&#xf…

H3C防火墙RBM对接交换机M-LAG典型配置

FW配置&#xff1a;FW1与FW2采用RBM组网&#xff0c;M-LAG Border的跨设备二层聚合口与RBM FW设备的设备内三层聚合口对接。FW主设备的设备内三层聚合口编号应与备设备的设备内三层聚合口编号保持一致。防火墙省略安全域和安全策略配置。 Border设备配置&#xff1a;采用M-LAG组…

嵌入式学习49-单片机2

指令周期 1M 机器周期 12M &#xff08;晶体震荡器产生&#xff09; 中断两种方式 …