如何保护用于客户登录的 API,而不会使其容易受到他人的攻击



我对使用angularjs进行开发非常陌生。 我正在使用angularjs创建一个用户登录系统。 我使用 json 数据使用 angularjs 创建了一个用户登录系统。 但是在控制器中使用我的 api 链接容易受到任何在我的登录页面源代码内的人的攻击。

我想保护我的 api 不受任何人的攻击。使用源代码可以帮助任何人查看我的平台的所有用户。此外,如果我正在散列密码,那么一些技术人员也可能会解码密码。

请帮助我使用 angular 或 json 来保护我的登录平台。

创建哈希密码时,可以在创建安全哈希密码后将 salt 值添加到该密码中。

您可以使用bcrypt

const salt = bcrypt.genSaltSync(+20);
const hash = bcrypt.hashSync(userId, salt);
return hash;

另一个用户可以解码此密码,但他们不能创建相同的密码。

bcrypt is not an encryption function, it's a password hashing function. Hashing is mathematical one-way functions, meaning there is no* way to reverse the output string to get the input string.
*of course only Siths deal in absolutes and there are a few attacks against hashes. But none of them are "reversing" the hashing.
create a password:
const salt = bcrypt.genSaltSync(+20);
const generatedPassword = bcrypt.hashSync(data, salt);
we can compare a hash password 
data=Test@123
hash=******
ex:const comparePassword = bcrypt.compareSync(data, hash);
You will get your password is matched or not

最新更新