Php Vue js与Laravel-登录表单安全

Php Vue js与Laravel-登录表单安全,php,laravel,vue.js,Php,Laravel,Vue.js,我在Vue js中有一个简单的应用程序,它可以在两种形式之间进行选择——使用短信或密码登录 下面的应用程序安全吗 使用密码登录的表单: <template> <div v-if="status !== 265" class="loginForm"> <label for="phone" class="">Phone</label> <input

我在Vue js中有一个简单的应用程序,它可以在两种形式之间进行选择——使用短信或密码登录

下面的应用程序安全吗

使用密码登录的表单:

<template>
 <div v-if="status !== 265" class="loginForm">
    <label for="phone" class="">Phone</label>
    <input type="text" class="form-control" v-model="fields.phone">
    <input type="hidden" id="phone" name="phone" v-model="fields.phone">
    <div v-if="errors && errors.phone" class="text-danger">
       <p v-for="item in errors.phone">{{ item }}</p>
    </div>

      ---> same with password
    <input  type="submit" class="" value="Submit">
 </div>
 <div v-else>
     <!-- redirect to dashboard -->
 </div>
</template>

<script>

export default {
    mixins: [ FormMixin ],

    data() {
        return {
            fields: {},
            errors: {},
            success: false,
            loaded: true,
            status: 0,
            'action': '/klient/customer/login-authorization-password',
        }
    },

    methods: {
        submit() {
            if (this.loaded) {
                this.loaded = false;
                this.success = false;
                this.errors = {};

                axios.post(this.action, this.fields).then(response => {
                    this.fields = {};
                    this.loaded = true;
                    this.success = true;
                    this.status = response.status;;
                }).catch(error => {
                    this.loaded = true;
                    if (error.response.status === 422) {
                        this.errors = error.response.data.errors || {};
                    }
                });
            }
        },

    },
}
</script>

在状态为267的响应之后,vue重定向到/customer/dashboard和PHP检查会话变量loggedIn。如果loggedIn为true,则用户可以使用其id访问数据。

您必须使用类似的包,而不必像
session::set('loggedIn',true)那样存储在会话中(请不要使用
TRUE
FALSE
NULL
,阅读PSR)。如果您不使用这样的软件包,您将搞乱许多与Laravel内置的身份验证和授权相关的事情。阅读有关它的文章。@matiaslauriti我会改变它。我指的是从vue表单到php控制器的数据传输的安全性。若数据有效,控制器返回状态代码,vue重定向到仪表板,控制器将检查用户是否使用Laravel Sanctum登录。我不在vue中编程,但我需要它来实现登录表单。如果数据通过HTTPS发送,则是安全的。我不会使用自定义http状态代码。最好返回一个标准的状态代码(403可能?),并在正文中返回一个消息或代码:<代码> -JSON([消息'=>‘仪表板’,403)< /C> > MaartenVeerman i在200-300之间返回代码,因为VUE不认为它是错误的。我知道这个应用程序非常原始,但如果安全的话,对我来说就足够了。我将用php完成其余的工作。非常感谢。
public function loginAuthorizationPassword(Request $request) {
        $data = request()->validate([
            'phone' => 'required|numeric',
            'password' => 'required|min:6'
        ]);

        $customer = \DB::connection('mysql2')
            ->table('customer')
            ->where('phone_login', $request['phone'])
            ->where('password', NULL)
            ->first();

        if(!$customer) return response()->json(null, 265); //wrong password or customer no exist


        if ($customer->password != NULL && Hash::check($request['password'], $customer->password)) {
            Session::set('loggedIn', TRUE);
            Session::set('id', $customer->id);
            return response()->json(null, 267); //return user is valid
        } else return response()->json(null, 265); //wrong password or customer no exist
    }