Hello there, I want some serious help, I have some JavaScript code that is a password for an HTML UI, so I want it to extract the password from Lua
Here is the JS Code
$(function () {
function display(bool) {
if (bool) {
$("#container").show();
} else {
$("#container").hide();
}
}
display(false)
window.addEventListener('message', function(event) {
var item = event.data;
if (item.type === "ui") {
if (item.status == true) {
display(true)
} else {
display(false)
}
}
})
// if the person uses the escape key, it will exit the resource
document.onkeyup = function (data) {
if (data.which == 27) {
$.post('http://AS_StealF/exit', JSON.stringify({}));
return
}
};
$("#close").click(function () {
$.post('http://AS_StealF/exit', JSON.stringify({}));
return
})
//when the user clicks on the submit button, it will run
$("#submit").click(function () {
//var randompass = Math.floor(Math.random() * 100) + 1;
let inputValue = $("#input").val()
if (inputValue.length >= 1001) {
$.post("http://AS_StealF/error", JSON.stringify({
error: "كلمة السر غير صحيحة"
}))
return
}
else if (!inputValue) {
$.post("http://AS_StealF/error", JSON.stringify({
error: "كلمة السر غير صحيحة"
}))
return
}
else if (inputValue == 99) {
$.post("http://AS_StealF/sucess", JSON.stringify({})
)
return
}
// if there are no errors from above, we can send the data back to the original callback and hanndle it from there
$.post('http://AS_StealF/main', JSON.stringify({
text: "كلمة السر غير صحيحة",
}));
return;
})
})
exactly here : else if (inputValue == 99) {
$.post(“http://AS_StealF/sucess”, JSON.stringify({})
)
return
and here is the lua code I want to get the password from,
Sure, when you are using $.post you can always add any paramter you want to get data.
for example: JSON.stringify({hello: parseInt(amount)})
Here is your code.
Everything @rcore and @Fixheko said is correct. I will just add my two cents: after you received password on client side - send it to server side for verification:
-- server.lua
local correctPassword = "seven-delta-snake"
RegisterNetEvent("password:verify", function(password)
local playerId = source
if password == correctPassword then
TriggerClientEvent("password:correct", playerId)
end
end)
--Server
local correctPassword = "seven-delta-snake"
RegisterNetEvent("password:verify", function(password)
if password == correctPassword then
TriggerClientEvent("password:correct", source, password)
end
end)
--Client
RegisterNetEvent("password:correct", function(password)
if password then
print("Password is correct")
else
print("Password is incorrect")
end
end)
I mean if you want to post data from JS to LUA
by adding paramter with some data for example:
//JavaScript
var amount = $(this).attr("data-amount");
if (amount > 0 ) {
$.post("http://AS_StealF/submitPassword", JSON.stringify({test: parseInt(amount)})
}
//Lua
RegisterNUICallback("submitPassword", function(data)
if tonumber(data.amount) ~= nil and tonumber(data.amount) > 0 then
print("Amount entered is ", data.amount)
end
end)
For all the people who helped me in this topic, I appreciate you all your help guys, but what I need is :
I need a random password, that changes when ever a specific event is triggered, and I want the password to be between 1,100 and I want it to be the same in Lua and JavaScript, hope you guys can help.